Reputation: 391
I have two table ,
2.district where DistCode, StCode, DistrictName
My code for first Drop down
<td><label for="studentstate"></label>
<select name="studentstate" id="studentstate">
<?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die('could not connect:'.mysql_error());
}
mysql_select_db("db_loan",$con);
$sqlstr="select StCode,StateName from state";
$result=mysql_query($sqlstr);
while($row=mysql_fetch_array($result))
{
echo '<option value="'.$row['StCode'].'">'.$row['StateName'].'</option>';
}
echo $sccode=$row['StCode'];
?>
</select></td>
Now i have try following for second dropdownlist where i want to show district name
<div id="result">
<input type="button" value="Reload"></input>
<select name="studentdist" id="studentdist">
<?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die('could not connect:'.mysql_error());
}
mysql_select_db("db_loan",$con);
$sqlstr="select DistCode,DistrictName from district where StCode='$sccode'";
$result=mysql_query($sqlstr);
while($row=mysql_fetch_array($result))
{
echo '<option value="'.$row['DistCode'].'">'.$row['DistrictName'].'</option>';
}
// echo $sccode=$row['DistCode'];
?>
</select></td>
</div>
Now if i what i should do for reload my div when select first value from drop down list
Please if you know please tell me how to do it without using ajex or jquery
After read suggestion from mirza i have updated my code as follow but still there it is not working
</head>
<script type="text/javascript">
$("#studentstate").change(function()
{
$("#studentdist").load("pag1.php?choice=" + $("#studentstate").val());
});
</script>
<body>
Upvotes: 1
Views: 51
Reputation: 1717
you need some JQuery Basic to do this task
<script type="text/javascript">
$("#first-choice").change(function() {
$("#second-choice").load("getter.php?choice=" + $("#first-choice").val());
});
</script>
getter.php replace with your php page name and it will work
Upvotes: 1