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 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    Islamabad
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    selection in <select> tag

    Dear friends
    I have a problem and I need Your Help
    let suppose we have a <SELECT> dropdown list and in which we have 5 options. If in javascript function we pass option no. how can we make that option selected.
    ENGR IRFAN HAIDER JAFFERY
    BE CIVIL, MCS (STUDENT)
    ISALAMABAD

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <script>
    function setIndex(index, selID) {
    var obj = document.getElementById(selID);
    obj.selectedIndex = index;
    }
    </script>
    
    (...HTML...)
    
    <span onClick="setIndex(3,'demo');">Set to 3</span>
    <select id="demo">
    <option value="blah1">blah1</option>
    <option value="blah2">blah2</option>
    <option value="blah3">blah3</option>
    <option value="blah4">blah4</option>
    </select>

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    Islamabad
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    THANK YOU

    THANKS BEETLE
    IT WORKS
    THANKS A LOT
    ENGR IRFAN HAIDER JAFFERY
    BE CIVIL, MCS (STUDENT)
    ISALAMABAD


  •  

    Posting Permissions

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