Hi
i'm having a form which contains 2 list boxes., 1st for category and 2nd for subcategory
the 1st list box contains the category lists., which is displayed from the database.,
and i want to display the corresponding subcategories in the 2nd list box when the category in the 1st listbox is selected.
So i hav called the ajax function in the onchange event of the listbox., and displayed the subcategories in the 2nd list box using xml Http request.,
which works well in firefox but not in IE.,
here is my code
[code=php]
//comes inside the table and category names are displayed from the database
<select name="category" id="category" onchange="oncha ngefn()">
<option selected="selec ted">[-------------S E L E C T-------------]</option>
<?
$res_cat=$ins->selectquery("s elect * from category");
while($line_cat =mysql_fetch_ar ray($res_cat,MY SQL_ASSOC))
{
?>
<option ><? echo $line_cat['catname'];?></option>
<?
}
?>
</select>
[/code]
<div id="change"></div>
and in my categorychange. php page,by getting the category name the corresponding subcategory'a are selected from database and displayed in the <div>tag specified.,
this is the code in the categorychange. php page.,
[code=php]
<?
$res_fn=$ins->selectquery("s elect * from subcategory where catid='$catid'" );
$i=0;
?>
<select name="subcatego ry">
<option selected="selec ted">[-------------S E L E C T-------------]</option>
<?
$res_fn=$ins->selectquery("s elect * from subcategory where catid='$catid'" );
while($line_fn= mysql_fetch_arr ay($res_fn,MYSQ L_ASSOC))
{
?>
<option value="<? echo $line_fn['subcatname'];?>"><? echo $line_fn['subcatname'];?></option>
<?
}
?>
</select>
[/code]
when runs in firefox it works well and the corresponding subcategory name is displayed when the category name is changed.,
but in IE i only get the default option.,
that is. <option selected="selec ted">[-------------S E L E C T-------------]</option>
no corresponding list is found.,
and even it is not displaying the subcategory list before the list item.,
could anyone help me??
regards
vijay
i'm having a form which contains 2 list boxes., 1st for category and 2nd for subcategory
the 1st list box contains the category lists., which is displayed from the database.,
and i want to display the corresponding subcategories in the 2nd list box when the category in the 1st listbox is selected.
So i hav called the ajax function in the onchange event of the listbox., and displayed the subcategories in the 2nd list box using xml Http request.,
which works well in firefox but not in IE.,
here is my code
Code:
<script type="text/javascript">
var id;
var action;
function ajaxFunction(cat)
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById("change").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET","categorychange.php?catname="+cat,true);
xmlHttp.send(null);
}
function onchangefn()
{
cat_val=document.form1.category.value;
ajaxFunction(cat_val)
}
</script>
//comes inside the table and category names are displayed from the database
<select name="category" id="category" onchange="oncha ngefn()">
<option selected="selec ted">[-------------S E L E C T-------------]</option>
<?
$res_cat=$ins->selectquery("s elect * from category");
while($line_cat =mysql_fetch_ar ray($res_cat,MY SQL_ASSOC))
{
?>
<option ><? echo $line_cat['catname'];?></option>
<?
}
?>
</select>
[/code]
<div id="change"></div>
and in my categorychange. php page,by getting the category name the corresponding subcategory'a are selected from database and displayed in the <div>tag specified.,
this is the code in the categorychange. php page.,
[code=php]
<?
$res_fn=$ins->selectquery("s elect * from subcategory where catid='$catid'" );
$i=0;
?>
<select name="subcatego ry">
<option selected="selec ted">[-------------S E L E C T-------------]</option>
<?
$res_fn=$ins->selectquery("s elect * from subcategory where catid='$catid'" );
while($line_fn= mysql_fetch_arr ay($res_fn,MYSQ L_ASSOC))
{
?>
<option value="<? echo $line_fn['subcatname'];?>"><? echo $line_fn['subcatname'];?></option>
<?
}
?>
</select>
[/code]
when runs in firefox it works well and the corresponding subcategory name is displayed when the category name is changed.,
but in IE i only get the default option.,
that is. <option selected="selec ted">[-------------S E L E C T-------------]</option>
no corresponding list is found.,
and even it is not displaying the subcategory list before the list item.,
could anyone help me??
regards
vijay
Comment