Hi I'm new to ajax, I've already created a drop down menu using php and loads my provinces dynamically from my database, now what is supposed to do is, if you click on any province in the drop down menu the cities have to appear on another page which are also in my database
heres my php code that loads my drop down menu.
would you please shed some light on how I'm going to go about tackling this problem using ajax because I cant seem to find anything helpful over the net.
thanxxx in advance!!!!
heres my php code that loads my drop down menu.
Code:
[<html>]
[<head>][<title>]<?php echo $title;?>[</title>]
[<h1>][<?php echo $heading;?>][</h1>]
[</head>]
[<body>]
[<?]
function writeCities($id)
{
$con = mysql_connect("localhost","root","");
if (!$con) die('Could not connect: ' . mysql_error());
mysql_select_db("msansi", $con);
$query = "SELECT cities FROM provinces WHERE id =";
$query .= $id;
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo $row[0];
}
function populateDropBox()
{
$con = mysql_connect("localhost","root","");
if (!$con) die('Could not connect: ' . mysql_error());
mysql_select_db("msansi", $con);
$result = mysql_query("SELECT id,title,cities FROM provinces");
while($row = mysql_fetch_array($result))
{
echo "<option value=$row[0]>" . $row['1']."</option>";
}
}
[?>]
function onChangeDropBox()
{
var selected =0;
selected = document.myform.province.value;
var t = "<? writeCities(9);?>";
document.myform.submit.value = t;
}
[<form name="myform">]
[<script type="text/javascript">]
[<select name = "province" onChange="onChangeDropBox();"/>]
[<? populateDropBox(); ?>]
[<input type ="submit" value="submit" onClick="showcities";/>]
[</form>]
[</script>]
[</body>]
{</html>]
thanxxx in advance!!!!
Comment