Help - Search - Members - Calendar
Full Version: Problem in Firefox but fine in Explorer
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
maneess
Following script works in Explorer but not in Mozilla Firefox please help me.

<html>
<body>
<script type="text/javascript">
var xmlhttp;

function showUser(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="test.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChange…
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").inn…
}
}

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>

<a href="#" value="1" onClick="showUser(this.value)">click problem</a>
</body>
</html>

test.php ==>

<?php
$q=$_GET["q"];
echo $q;
?>

when i click on CLICK PROBLEM it display "1" in explorer but in Firefox it display "undefined". Whats the problem?
Above code works fine in Internet Explorer but not in Firefox 3
Demonslay
For one thing, please post code wrapped in a code box using BBCode. When I went to copy your code and test it out, it had alot of cut off parts where the forum added ellipses.

As for your problem, I think the fact is that anchors (<a>) don't have a value attribute by their definition. The fact that IE would actually let you do that doesn't really shock me with its in-aptitude to follow by W3C standards, whereas Firefox can't figure out why you are using an attribute that shouldn't exist in that particular tag.

If you are trying to send an AJAX request on the clicking of something, and want it to send the value of that element, I'd say you could use a select menu and make the showUser function invoked by its onChange handler like so.

CODE
<select name="suspect" onchange="showUser(this.value)">
<optgroup label="--Select a Suspect--">
<option value="">A Ninja</option>
<option value="green">Mr. Green</option>
<option value="peacock">Mrs. Peacock</option>
<option value="scarlet">Ms. Scarlet</option>
<option value="plum">Mr. Plum</option>
</optgroup>
</select>


Hope that helps.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.