Results 1 to 2 of 2

Thread: How do you iterate through ALL the drop-down menu (select) objects on the form in css

  1. #1
    Join Date
    Jan 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do you iterate through ALL the drop-down menu (select) objects on the form in css

    can any one reply me please urgent

  2. #2
    Join Date
    Aug 2004
    Posts
    9,878
    Thanks
    3
    Thanked 962 Times in 951 Posts
    Blog Entries
    15

    Default

    I think you mean using JavaScript (CSS is for styling elements only). In JavaScript, there is the SELECT object, plus the OPTIONS array that together let you access/loop through all options within a SELECT menu. For example:

    Code:
    <form>
    <select id="myselect">
    <option value="cat">Option 1</option>
    <option value="dog">Option 2</option>
    <option value="bear">Option 3</option>
    </select>
    </form>
    
    <script type="text/javascript">
    var selectobject=document.getElementById("myselect")
    for (var i=0; i<selectobject.length; i++){
    alert(selectobject.options[i].text+" "+selectobject.options[i].value)
    }
    
    </script>
    More info here: http://www.javascriptkit.com/jsref/select.shtml

Bookmarks

Posting Permissions

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