Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

jQuery and drop down lists

  • 26-10-2007 4:27pm
    #1
    Registered Users, Registered Users 2 Posts: 528 ✭✭✭


    Hi

    I am trying to use JQuery with a drop down list. I cannot get the selected index.

    I know how to register the event for my dd list :

    $("select#myddl").change(function(){


    });


    How do I translate the following code in JQuery :

    How do I go about retreiving the selected value of a dropdown list using jquery?


    <select onchange="f(this.selectedIndex)">
    <option></option>
    <option></option>

    </select>


Comments

  • Posts: 0 [Deleted User]


    Well jquery objects have a get() method, which returns a DOM element. So you can use properties like selectedIndex. eg. $("myEl").get(0).innerHTML = "Example"; would access the native javascript object of 'myEl' and change it's innerHTML.


  • Registered Users, Registered Users 2 Posts: 528 ✭✭✭Drexl Spivey


    Well jquery objects have a get() method, which returns a DOM element. So you can use properties like selectedIndex. eg. $("myEl").get(0).innerHTML = "Example"; would access the native javascript object of 'myEl' and change it's innerHTML.


    Sounds good. How do you return the index of an option selected using JQuery:

    <select>
    <option value="A">a</option><option value="B">b</option><option
    value="C">c</option>
    </select>


    I want to return 0, 1 and 2 when the above options are selected (in an alert box for ex.)


    How would you go about it?

    I cannot find the answer on jquery.com, google, ....


    Thanks


  • Registered Users, Registered Users 2 Posts: 3,428 ✭✭✭randombar


    Not sure if it's the same thing but I returned javascript commands from an ajax piece I'm using, those javascript commands then populate the select box
    function addNewTreatment( id, name ) {
    document.forms['formname'].elements[ 'treatmentid' ][ document.forms['formname'].elements[ 'treatmentid' ].length ] = new Option( name, id );
    }
    
    


  • Closed Accounts Posts: 1 mariochampion


    hey,

    don't know if you ever found this out.

    var varname =$("select#selectname").val();

    enjoy
    mario


Advertisement