SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Location
    Canada
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    updating the selectedIndex property of a select menu

    I've got a form with 2 identical select menus. They are named select1, select2. I have a checkbox called copybox. I would like to select something in one menu, click the checkbox, and have the selected index of the other menu match the first one. Here is the code I'm using. It does not work and I"m unable to figure out why.

    Code:
    <form name="myform">
    <select name="select1">
    <option value="one">Option 1
    <option value="two">Option 2
    </select>
    
    <input type="checkbox" name="copybox" onclick="copystuff();">
    
    <select name="select2">
    <option value="one">Option 1
    <option value="two">Option 2
    </select>
    </form>
    and the copystuff() function:

    Code:
    <script language="JavaScript">
    function copystuff()
    {
      window.document.myform.select2.selectedIndex = window.document.myform.select1.selectedIndex;
    }
    </script>
    This is a simplified version of a larger form so I really need this particular solution (checkbox will copy values) to work. I should mention that when I tried removing the 'value' property from the 'option' tag, the copystuff() function worked. I think this has something to do with it but I don't know what.

    Thanks for all the help
    Pras
    Last edited by Pras; Feb 17, 2002 at 19:50.

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might work:
    function copystuff() {
    document.myform.select2.options[document.myform.select1.selectedIndex].select();
    }
    ck :: bringing chris to the masses.

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Location
    Canada
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I tried that but no go, I'm afraid. Any other suggestions?

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Location
    Canada
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I solved the problem. I had named the form incorrectly!


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
  •