The purpose of this code is to show the subjects handled by a teacher
onchange of the select list. if I select one teacher, the select element
below it should display all corresponding subjects of the selected teacher..
It works in Mozilla firefox but not in IE...
Code: Select all
//THIS IS MY JAVASCRIPT CODE
<script type="text/javascript">
var xmlhttp
function show(id)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="showsubjects.php";
url=url+"?subjects="+id;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("subjname").innerHTML=xmlhttp.responseText;
}
}
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;
}
</script>
//this is my HTML
<td >
<select name="subjects" style="width:200;" onChange="show(this.value)">
<option value="0">----- Select Faculty -----</option>
<?php
$result = mysql_query("SELECT * FROM faculty");
while($row = mysql_fetch_array($result))
{
echo '<option value="'.$row['facid'].'">'.$row['facname'].'</option>';
}
?>
</select>
</td>
<td >
<select name="subjname" style="width:200;" id="subjname">
</select>
</td>
THIS IS MY showsubjects.php file:
<?php
include 'database/dbconnection.php';
if(isset($_GET['subjects'])){
$facid=$_GET['subjects'];
//select all the subjects of the selected faculty
$result = mysql_query("SELECT A.*, B.* FROM itproject.faculty_subject as A, itproject.subject as B WHERE A.facid='$facid' and A.subjid=B.subjid");
while($row = mysql_fetch_array($result))
{
echo '<option value="'.$row['subjid'].'">'.$row['subjname'].'</option>';
}
}
?>
mY problem is it would not work in IE... I think this is not about the IE issue that it would
not support some javascripts... I think there's something wrong with my code... OR, do you
have alternatives for my code in which I can do my purpose which is to display all the subjects
handled by the teacher ???