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 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2010
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Link different options in my drop down form

    Hello,
    Im currently working on a form where a person selects from a drop down list, a state, and then city options become available in another drop down list.
    I have that part working perfectly, but Im not sure how I would then make it so when a city is selected and the submit button is pushed, it will go to a link corresponding with the city.
    Heres my javascript/html

    Code:
    <script type="text/javascript">
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    function fillSelect(country) {
    
    var url = "http://****************/city.php?country=" + escape(country);
    
    xmlhttp.open("GET", url, true);
    
    xmlhttp.onreadystatechange =go;
    xmlhttp.send(null);
    }
    function go() {
    if (xmlhttp.readyState == 4) {
    if (xmlhttp.status == 200) {
    var response = xmlhttp.responseText;
    var list=document.getElementById("City");
    var cities=response.split('|');
    for (i=1; i<cities.length; i++) {
       var x=document.createElement('option');
       var y=document.createTextNode(cities[i]);
       x.appendChild(y);
       list.appendChild(x);
       }
      }
     }
    }
    function display()
    {
    var country=document.getElementById('country');
    country.onchange=function() {
    if(this.value!="") {
      var list=document.getElementById('City');
      while (list.childNodes[0]) {
      list.removeChild(list.childNodes[0])
                                  }
    fillSelect(this.value);
    }
    }
     fillSelect(country.value)
    }
    </script>
    <body onload="display()">
    <center><form name="select" id="select">
    <select name="country" id="country" >
    <option selected="selected">Select State</option>
    <option>Michigan</option>
    </select>
    <select name="City" id="City" >
    <option>Select City</option>
    </select>
    </form><br /><br />
    <input name="submit" type="submit" value="Submit" />
    and heres my php

    Code:
    <!-- Script by hscripts.com -->
    <?php
    echo("ada");
    $country=$_GET['country'];
    echo($country);
    function doIt($country) {
    switch ($country) {
    case "Michigan":
    return array('Traverse City');
    break;
    }
    }
    $cities=doIt($country);
    foreach ($cities as $city) 
    {
    echo '|'.$city;
    }
    ?>

    Thanks a lot for your help

  • #2
    New Coder
    Join Date
    Dec 2010
    Location
    Orlando, FL
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I setup that code on my test server and it does not populate the city correctly, so technically no that part is not working correctly either.

    Explain more than just a couple lines what you have already done and what you're trying to do.

    http://****************/city.php <- invalid argument

    I would like to help but i don't have time to pick apart the entire code to figure out exactly how you are trying to do it, you need to explain it more to us if you want help.

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by tripflex View Post
    http://****************/city.php <- invalid argument

    I would like to help but i don't have time to pick apart the entire code to figure out exactly how you are trying to do it, you need to explain it more to us if you want help.
    http://****************/city.php?country=Michigan


  •  

    Posting Permissions

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