Onblur not working in mozilla, fine in IE

Discussion in 'Javascript' started by rjones326@gmail.com, Jan 15, 2007.

  1. Guest

    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>
    , Jan 15, 2007
    #1
    1. Advertising

  2. ASM Guest

    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;
    }

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
    ASM, Jan 15, 2007
    #2
    1. Advertising

  3. ASM Guest

    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;
    }
    }

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
    ASM, Jan 15, 2007
    #3
  4. Guest

    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 :)


    ASM wrote:

    > 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;
    > }
    > }
    >
    > --
    > Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    > Stephane Moriaux and his (less) old Mac already out of date
    , Jan 16, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    6
    Views:
    322
    Blinky the Shark
    Sep 27, 2007
  2. Lord of Chaos
    Replies:
    0
    Views:
    450
    Lord of Chaos
    Jan 11, 2010
  3. EviL KerneL

    OnBlur not working !

    EviL KerneL, Sep 28, 2004, in forum: Javascript
    Replies:
    5
    Views:
    215
    Michael Winter
    Sep 30, 2004
  4. anand basha

    What is the replacement for onBlur in Mozilla

    anand basha, Jan 21, 2006, in forum: Javascript
    Replies:
    0
    Views:
    87
    anand basha
    Jan 21, 2006
  5. C#_learner
    Replies:
    3
    Views:
    116
    C#_learner
    Jun 26, 2006
Loading...

Share This Page