Results 1 to 2 of 2

Thread: Changing the value of a drop down

  1. #1
    Join Date
    Mar 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Changing the value of a drop down

    I have a strange request for help.

    I have a form that has three identical select boxes. All of the select option tags are exactly the same and in the same order. Each select box has a unique ID number.

    What I was wondering is if it would be possible to do an onchange event that if someone selects a value in one of the drop downs it automatically changes it on the other two drop downs.

    I'm not even sure where to begin here.

    Thanks,
    -Matt

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Simple enough...
    Code:
    <form action="" name="formname">
      <select name="select0">
        <!-- ... options ... -->
      </select>
      <select name="select1">
        <!-- ... options ... -->
      </select>
      <select name="select2">
        <!-- ... options ... -->
      </select>
      <!-- ... more ... -->
    </form>
    <script type="text/javascript">
      var changeHandler = function() {
        for(var i = 0, e = document.forms['formname'].elements; s = e['select' + i]; ++i)
          s.selectedIndex = this.selectedIndex;
      };
      for(var i = 0, e = document.forms['formname'].elements; s = e['select' + i]; ++i)
        s.onchange = changeHandler;
    </script>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •