Hello and welcome to our community! Is this your first visit?
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
    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. #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,608 Times in 2,586 Posts
    Try this:-

    <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>
    <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

    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