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
Problem in Firefox but fine in Explorer
Started by maneess, Aug 21 2009 03:31 AM
1 reply to this topic
#1
Posted 21 August 2009 - 03:31 AM
#2
Posted 04 October 2009 - 12:57 AM
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.
Hope that helps.
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.
<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.
Edited by Demonslay, 04 October 2009 - 12:58 AM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
