Page 1 of 1

PHP,Ajax & Browser Problem

Posted: Wed Apr 01, 2009 12:37 am
by yoursanjay
Hi
I have written a PHP & ajax script which dynamically select a dependent dropdown select box. The script is running perfectly in Firefox but not in Internet Explorer & Safari. I have to run the script in all the browser perfectly. If there is any error in my script,please help me to solve it out. I don't know DOM technology. I have to run the script perfectly in IE.

Code: Select all

 
<select name="category" size="1" class="body-text-grey" onchange="showDivision(this.value)">
<option selected="selected" value="blank">Choose a Category</option>
<?php
$res=mysql_query("select * from mbehub_categories where parent_id='0' order by id") or die (mysql_error());
while ($rw=mysql_fetch_array($res))
{
 
?>
<option value="<?php echo $rw['id'];?>"><?php echo $rw['name'];?></option>
<?php
}
?>
</select>
 
<tr>
<td height="22" align="left" valign="top" class="body-text-grey-2">Primary Area of Interest </td>
<td height="22" colspan="2" align="left" valign="top">
<select name="division" size="1" class="body-text-grey" id="txtDivision">
<option selected="selected">Select Area of Interest</option>
</select>
 
 
</td>
</tr> 
 
And the Ajax is :

Code: Select all

 
// JavaScript Document
var xmlHttp;function showDivision(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="division.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtDivision").innerHTML=xmlHttp.responseText;
}
}function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
 

Re: PHP,Ajax & Browser Problem

Posted: Wed Apr 01, 2009 12:52 am
by miyur
what issue are you facing exactly?
well, what i could see in your ajax script was that on line number 3 and line number 25, you have declared xmlhttp as var twice. just do it once on the top. may be that will solve the issue. let us know if that works out and if not, tell us what exactly is your problem?

Re: PHP,Ajax & Browser Problem

Posted: Wed Apr 01, 2009 1:12 am
by yoursanjay
No, the problem is not solved yet.
The problem which I am facing:
function:
The "category" drop down select box select a category and depend from this selected category the list of area of interest will be shown in" Area of Interest" select box. It is dependent dynamic drop down select box.
problem: this functionality is perfectly shown in Firefox but not in Internet Explorer. Whenever a category is selected from category drop down down select box, Area of Interest drop down box remains blank.
I need to show the script perfectly in Internet Explorer.

Re: PHP,Ajax & Browser Problem

Posted: Wed Apr 01, 2009 1:24 am
by novice4eva
txtDivision is select item. You cannot use innerHTML in select!! OR could you...i don't think that's a good idea anyways.
Go for

Code: Select all

 
        txtDivision=document.getElementById('txtDivision ');
        txtDivision .options[0].text=somevalue;
        txtDivision .options[0].value=somevalue;
                txtDivision .options[1].text=somevalue;
        txtDivision .options[1].value=somevalue;
         
you would need to format the ajax response using some character combination to separate text and value pairs for select. Then using the split function of javascript integrate similar logic to what i've posted .

Re: PHP,Ajax & Browser Problem

Posted: Wed Apr 01, 2009 6:06 am
by miyur
i think the problem is solved now.. innerHTML was the culprit..:)