Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Internet & the Web (https://www.askmehelpdesk.com/forumdisplay.php?f=177)
-   -   How to set the selection of a combo list (https://www.askmehelpdesk.com/showthread.php?t=26431)

  • May 22, 2006, 03:02 AM
    xuanmanh
    How to set the selection of a combo list
    Does anyone know wherer there is a javascript method to set the selection of a combo list?
  • May 22, 2006, 04:49 AM
    LTheobald
    Something like this maybe...

    Imagine you had the following list:
    Code:

    <select name="testselect">
        <option value="first">first option</option>
        <option value="second">second option</option>
        <option value="third">third option</option>
    </select>

    You could then have a function like below:
    Code:

    function selectMe(val) {
        for (var i=0; i<document.all.testselect.length; i++) {
            if (document.all.testselect.options[i].value == val) {
                document.all.testselect.options[i].selected = true;
            }
        }
    }

    So if you called selectMe with a value of "second", it would select the second option in the dropdown.

    Is that what you meant?
  • Jun 1, 2006, 04:59 AM
    xuanmanh
    Yes, absolultely right, My problem was solved so well. Thank you very much

  • All times are GMT -7. The time now is 07:08 AM.