PHP,Ajax & Browser Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yoursanjay
Forum Newbie
Posts: 17
Joined: Sat Feb 23, 2008 12:21 pm

PHP,Ajax & Browser Problem

Post 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;
}
 
miyur
Forum Newbie
Posts: 15
Joined: Sat Jan 10, 2009 9:06 am

Re: PHP,Ajax & Browser Problem

Post 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?
yoursanjay
Forum Newbie
Posts: 17
Joined: Sat Feb 23, 2008 12:21 pm

Re: PHP,Ajax & Browser Problem

Post 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.
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: PHP,Ajax & Browser Problem

Post 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 .
miyur
Forum Newbie
Posts: 15
Joined: Sat Jan 10, 2009 9:06 am

Re: PHP,Ajax & Browser Problem

Post by miyur »

i think the problem is solved now.. innerHTML was the culprit..:)
Post Reply