Onblur not working in mozilla, fine in IE

R

rjones326

Hi,

I'm stupendously mystified by this strange activity. I cannot for the
life of me figure out why this will not work in mozilla. I've spent
hours mucking around with it. The php file is just an echo statement
now to simplify for the moment. If instead of calling the replace
function I've also tried putting in an alert function. Alert works,
the calling the php file does not.

Any suggestions greatly appreciated, I've never encountered such
difficult functionality as with javascript in firefox compared to IE.
Might just be my luck though...



<html>
<head>
<script language="javascript" type="text/javascript">
var url = "poo.php?pc=" ;


function aHttpResponse() {
if (http.readystate == 4) {
results = http.responseText ;
document.getElementById('state').value=http.responseText ;
}

}
function fiction(){
alert("yes") ;
}
function callPHPResponse() {
var pcode = document.getElementById("postcode").value ;
http.open("GET",url+escape(pcode),true) ;
http.onreadystatechange = aHttpResponse ;
http.send(null) ;
}


function getHTTPObject() {
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
return http_request ;
}
var http = getHTTPObject() ;

</script>

</head>
<form action="post">
<table width="800">
<td width="100">Postcode</td>
<td width="700"><input type="text" name="postcode" id="postcode"
size="5" onblur="callPHPResponse();"></td>
</tr>
<tr>
<td width="100">State</td>
<td width="700"><input type="text" name="state" id="state"
size="50"></td>
</tr>
<tr>

</table>
</form>
</html>
 
A

ASM

(e-mail address removed) a écrit :
Hi,

I'm stupendously mystified by this strange activity. I cannot for the
life of me figure out why this will not work in mozilla. I've spent
hours mucking around with it. The php file is just an echo statement
now to simplify for the moment. If instead of calling the replace
function I've also tried putting in an alert function. Alert works,
the calling the php file does not.

Any suggestions greatly appreciated, I've never encountered such
difficult functionality as with javascript in firefox compared to IE.
Might just be my luck though...

what about :

function callPHPResponse() {
http = getHTTPObject(); // a new XHR isn't necessary on each call ?
var pcode =
... etc ...
}


Does code returned by php is understood ?

XMLHttp Object :

function getHTTPObject() {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
// http_request.overrideMimeType('text/html');
}
}
else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (!http_request) {
alert('Impossible to create XMLHTTP instance');
return false;
}
return http_request;
}


Response comes back ?

function aHttpResponse() {
if (http.readystate == 4) {
results = http.responseText ;
alert('result = '+result);
document.getElementById('state').value = result;
}
 
A

ASM

ASM a écrit :
Response comes back ?

function aHttpResponse() {
if (http.readystate == 4) {

function aHttpResponse() {
if (http.readystate == 4) {
results = http.responseText ;
alert('result = '+results);
document.getElementById('state').value = results;
}
}
 
R

rjones326

Believe it or not that whole time it was because of

if (http.readystate == 4)

rather than

if (http.readyState == 4)

Works with the lowercase in IE.. does not in mozilla. I went back
through my numerous revisions of this code changing that and every time
the code worked straight away.

What a collosal waste of time. Lucky its paid time :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,821
Messages
2,569,748
Members
45,726
Latest member
RaleighAll

Latest Threads

Top