...

View Full Version : jQuery how to select from drop down



capt_nemo777
12-01-2010, 06:29 PM
question: how to select the 7th value in my dropdown menu ?

http://i52.tinypic.com/iggn0x.jpg

this drop down menu is generated by my php function inside a model of my mvc app like this



public function getSecretQuestions()
{
return array(
0 => 'What is your favourite Colour?',
1 => 'What is your mothers Maiden Name?',
2 => 'What is your Pets Name?',
3 => 'What was your first telephone number?',
4 => 'What was your favourite teachers name?',
5 => 'What is the title of your favourite film?',
6 => 'What is the name of your favourite book?',
7 => 'Write my own question',
);
}


so how am i gonna select the 7th key value pair using jquery given the id of the drop down menu in order for me to show a text box ? :confused:

SB65
12-01-2010, 08:49 PM
If your resultant html is similar to:


<select id="selector">
<option>One</option>
<option>Two</option>
<option>Three</option>
<option>Four</option>
<option>Five</option>
<option>Six</option>
<option value="Number seven">Seven</option>
</select>

then


$('#selector').children().eq(6).val()

will return the 7th option value - "Number seven" in my example.

If you're trying to set the seventh option as selected:



$('#selector').children().eq(6).attr('selected','selected');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum