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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Match user input to predefined list to determine next page

    I am trying to write a basic code to ask a user to input his zip code that will then be checked against a list of predefined zip codes. if input is matching user goes to one url if not matching goes to another.

    any help would be great

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,308
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Try this:-

    Code:
    <html>
    <head>
    
    <select id = "zipcodes" onchange = "checkzip()">
    <option value = 0> Select your zip code</option>
    <option value = 12345>12345</option>
    <option value = 23456>23456</option>
    <option value = 34567>34567</option>
    <option value = "Other">Another zip code</option>
    </select>
    
    <script type="text/javascript">
    
    function checkzip() {
    var z = document.getElementById("zipcodes").value;
    if (z == 0) {
    return false;  // do nothing
    }
    if (z == "Other") {
    window.location.href = "http://www.google.com"  // replace by the actual url
    }
    else {
    window.location.href = "http://javascriptkit.com"  // replace by the actual url
    }
    
    }
    
    </script>
    </body>
    </html>

    They are not inferior teams, they are just not as good. - Commentator Radio 5 Live

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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