ok i have a AJAX drop down list for Country that when slected looks up data from the database and fills the next drop down list with the right data.
The problem im having is i cant get the value from the second drop down list to post with the rest of the form??? Can anyone help or give ideas on when its not working.
here is the code.
HTML
<html>
<head>
<script type="text/javascript" src="selectCountry.js"></script>
</head>
<body>
<form action="main2.php" method ="POST">
Country:
<select onchange="showCountry(this.value)" name="country" >
<option value="">Select one</option>
<option value="1">US</option>
<option value="2">UK</option>
<option value ="3">France</option>
</select>
<input type='submit' value='submit'>
</form>
<p id="here">City: <input type='text' name="city"></p>
</form>
</body>
</html>
JAVA SCRIPT
var xmlhttp;
function showCountry(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support HTTP Request!");
return;
}
var url="getCountry.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("here").innerHTML=xmlhttp.responseText;
}
else
{
document.getElementById("here").innerHTML = '<img src="ajax-loader.gif"> Loading..';
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
PHP
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ajax_demo", $con);
if ($q == 1)
{
$sql= mysql_query("SELECT * FROM states");
echo "State: ";
echo "<select name='state'>";
echo "<option value=''>Select one</option>";
while($row = mysql_fetch_array($sql))
{
echo "<option value ='1'>".$row['state']."</option>";
}
echo "</select>";
echo "<p>City: <input type='text'></p>";
}
else if ($q == 2)
{
$sql= mysql_query("SELECT * FROM ukTowns");
echo "City: ";
echo "<select name='city'>";
echo "<option value=''>Select one</option>";
while($row = mysql_fetch_array($sql))
{
echo "<option value ='1'>".$row['town']."</option>";
}
echo "</select>";
}
else if ($q != 1 || $q !=2)
{
echo "<p>City: <input type='text'></p>";
}
mysql_close($con);
?>
thanks for looking ....:quiet: