Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts

    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 ?

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,950
    Thanks
    9
    Thanked 724 Times in 718 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •