...

View Full Version : Link different options in my drop down form



hheyh222
12-16-2010, 04:03 PM
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



<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



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

tripflex
12-16-2010, 06:41 PM
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.

Inigoesdr
12-17-2010, 03:22 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum