Hi
all
I am using a list box which is displaying the values. when user select the value in the list box, on change event I called ajax function which will takes it to antoher php url . In this php it is checking the database and displaying the alert box. but I am not getting the alert box.
Here is the code
<?php
include(“config1.php”);
$result= mysql_query(“select vehicle_id from vehicle_master where vehicle_type= ‘1’ and active_status=‘0’ order by vehicle_id”);
echo"<form>“;
echo '<select name=“vehicle_id” id=“vehicle_id” class=“STYLE” style=” width:180px; height:80px; background-color: #CCCCFF;" size=“4” onChange=“showUser(this.value)”>‘;
echo "<option value=’'>Select </option>";
while($row=mysql_fetch_array($result))
{
$cab=$row['vehicle_id'];
echo "<option value='$cab'>$cab";
}
echo"</select>";
echo"</form>";
echo"<br />“;
echo”<div id=‘txtHint’>“;
echo”</div>";
echo"</body>“;
echo”</html>";
?>
</select>
</label>
</td>
javascript function
<script type=“text/JavaScript”>
function showUser(str)
{
if (str.length==0)
{
document.getElementById(‘txtHint’).innerHTML=“”;
return;
}
var url=“/tms/testproject/testforms/testjax.php”;
url=url+“?q=”+str;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(‘txtHint’).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,url,true);
xmlhttp.send();
}
</script>
php file
<?php
$q=$_GET[“q”];
include(“config1.php”);
$no_vehicles=mysql_query(“SELECT * from driver_master WHERE vehicle_id = '”.$q."’ and active_status=0 " )or
die(mysql_error());
$num=mysql_num_rows($no_vehicles);
if($num>2)
{
echo ‘<script language=“javascript”>’;
echo ‘alert(“Please delete the driver before adding the new driver”)’;
echo ‘</script>’;
}
?>
When user selects the vehicle id in the list box it should check how many drivers on that vehicle if it is more than 2 it should display the alert with out submitting the form.
please help me out to resolve the issue
Thanks
MD. Samiuddin