i have a drop down select list and a button in which i have inserted an onclick event so that whenever anyone is clicking on that button it will call a function which is basically includes an ajax and when on executing it will include a php file. In my php file it is taking the value from the selected drop down list and after that it will display an alert option but it is not displaying any alert.
Below is my code:-
<html>
<head>
<script>
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
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","user.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users1" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>
user.php
<?php
$q=$_GET["q"];
if($q ==1)
{
echo '<script type="text/javascript">
alert("Hello")
</script>';
}
else {
echo "No";
}
?>
Any help would be appreciated much and thanks for your help in advance:)