SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Tacoma, WA
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing 2 Select Boxes

    I have a select box that lists out all the states of the USA and if a state is selected I want the country select box with the value of "US" to be selected.

    Then if the country select box changes anything from the value of "US" I want the states select box to change to the value of "".

    How do I do this?

  2. #2
    SitePoint Addict
    Join Date
    Jul 2000
    Posts
    201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this ...
    HTML Code:
    <html>
    <head>
    <script language="JavaScript">
    
    function set_country(state) {
      if (state!="") {
        document.form1.country.value = "US";
      }
    }
    
    function set_state(country) {
      if (country!="US") {
        document.form1.state.value = "";
      }
    }
    
    </script>
    </head>
    
    <body>
    
    <form name="form1">
    
    <select name="state" onchange="set_country(this.value);"> 
    <option value=""></option> 
    <option value="Alabama">Alabama</option> 
    <option value="Alaska">Alaska</option> 
    <option value="California">California</option> 
    </select> 
    
    <select name="country" onchange="set_state(this.value);"> 
    <option value=""></option> 
    <option value="Canada">Canada</option> 
    <option value="Mexico">Mexico</option> 
    <option value="US">US</option> 
    </select> 
    
    </form>
    
    </body>
    </html>

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Tacoma, WA
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That doesn't work. Cause you need to select the index and set it to selected. But thanks anyways.


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
  •