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

Javascript Drop Down Lists- Check whats selected?

  • 26-04-2009 12:13pm
    #1
    Registered Users, Registered Users 2 Posts: 3,992 ✭✭✭


    Is there any way to check what has been selected with a drop down menu??
    For example?
    <select name="select">
    <option value=1>Answer 1</option>
    <option value=2>Answer 2</option>
    </select>
    

    I know that for a checkbox
    <input type="checkbox" name=answers value=1 />Answer 1
    

    i can use ".checked" in the js function to see if its selected. But what do i use for just a drop down menu?

    Cheers

    EDIT: Forgot at add, the users of this will be selecting their choice and pressing a submit button to send their answer.


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 9,035 Mod ✭✭✭✭mewso


    Well my preference is to use an id:-
    <select id="myselect">
    <option value=1>Answer 1</option>
    <option value=2>Answer 2</option>
    </select>
    

    so the script is:-
    var select = document.getElementById("myselect");
    var selIndex = select.selectedIndex;
    var opt = select.options[selIndex];
    

    I assume if you are asking you want to do it in javascript but you mention the user will be submitting the form which will often mean you'll want to do the checking on the server which is a different matter.


Advertisement