Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-01-2010, 05:29 PM   PM User | #1
capt_nemo777
New Coder

 
Join Date: Jul 2008
Posts: 63
Thanks: 12
Thanked 0 Times in 0 Posts
capt_nemo777 is an unknown quantity at this point
Question how to select from drop down

question: how to select the 7th value in my dropdown menu ?



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

PHP Code:
public function getSecretQuestions()
    {
        return array(
            
=> 'What is your favourite Colour?',
            
=> 'What is your mothers Maiden Name?',
            
=> 'What is your Pets Name?',
            
=> 'What was your first telephone number?',
            
=> 'What was your favourite teachers name?',
            
=> 'What is the title of your favourite film?',
            
=> 'What is the name of your favourite book?',
            
=> '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 ?
capt_nemo777 is offline   Reply With Quote
Old 12-01-2010, 07:49 PM   PM User | #2
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,817
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
If your resultant html is similar to:

Code:
<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

Code:
$('#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:

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

Last edited by SB65; 12-01-2010 at 07:51 PM..
SB65 is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:43 PM.


Advertisement
Log in to turn off these ads.