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
Expand|Select|Wrap|Line Numbers
- <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>
Expand|Select|Wrap|Line Numbers
- //comes inside the table and category names are displayed from the database
- <select name="category" id="category" onchange="onchangefn()">
- <option selected="selected">[-------------S E L E C T-------------]</option>
- <?
- $res_cat=$ins->selectquery("select * from category");
- while($line_cat=mysql_fetch_array($res_cat,MYSQL_ASSOC))
- {
- ?>
- <option ><? echo $line_cat['catname'];?></option>
- <?
- }
- ?>
- </select>
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.,
Expand|Select|Wrap|Line Numbers
- <?
- $res_fn=$ins->selectquery("select * from subcategory where catid='$catid'");
- $i=0;
- ?>
- <select name="subcategory">
- <option selected="selected">[-------------S E L E C T-------------]</option>
- <?
- $res_fn=$ins->selectquery("select * from subcategory where catid='$catid'");
- while($line_fn=mysql_fetch_array($res_fn,MYSQL_ASSOC))
- {
- ?>
- <option value="<? echo $line_fn['subcatname'];?>"><? echo $line_fn['subcatname'];?></option>
- <?
- }
- ?>
- </select>
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="selected">[-------------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