Reply
onblur failing / not initiating
Old 04-04-2008, 05:08 PM onblur failing / not initiating
Super Talker

Posts: 126
i am using the following AJAX request method. Most of you probably use this script allready as it seems to be everywhere online. I use it often with out issue... until now.

What I'm finding is that if the click used to initiate the onblur() used like
Code:
<input type="text" id="qty" name="qty" value="" onblur="makeRequest('ajax_insert.php?field_name=qty&field_value=',this.value);">
is on either a link or from submit button, the onblur() never gets called. In my code, the onblur() has to work if the user goes strait for the submit button before clicking anywhere else.

Any ideas on how to get it to call onblur() and refresh in a one click process? Thanks much for the help.

My AJAX code
Code:
function makeRequest(url, parameters) { 

    http_request = false;

    if (window.ActiveXObject) { // IE

        try {

            http_request = new ActiveXObject("Msxml2.XMLHTTP");

        } catch (e) {

            try {

                http_request = new ActiveXObject("Microsoft.XMLHTTP");

            } catch (e) {}

        }

    } else if (window.XMLHttpRequest) { // Mozilla, Safari, Sometimes IE7...

        http_request = new XMLHttpRequest();

        if (http_request.overrideMimeType) {

            // set type accordingly to anticipated content type
            http_request.overrideMimeType('text/xml');
            // http_request.overrideMimeType('text/html');

        }else{ alert('Did not create *http_request.overrideMimeType*'); return false; }

    } 

    if (!http_request) {

        alert('Cannot create XMLHTTP instance');
        return false;

    }

    http_request.onreadystatechange = alertContents;

    // FOR POST VARS
    //http_request.open('POST', url, true);
    //http_request.send(parameters);

    // FOR GET VARS
    //alert(url + parameters);
    http_request.open('GET', url + parameters, true);
    http_request.send(null);
    
}

function alertContents() {
    if (http_request.readyState == 4) {
     if (http_request.status == 200) {
        //alert(http_request.responseText);
        result = http_request.responseText;
        document.getElementById('myspan').innerHTML = result;
     } else {
        alert('There was a problem with the request.');
     }
    }
}
empiresolutions is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-05-2008, 04:58 AM Re: onblur failing / not initiating
chrishirst's Avatar
Super Moderator

Posts: 11,865
Location: Blackpool. UK
A "click" won't be triggering onblur() as the onblur event is called when an object loses focus. If the object changes the location of the window when it gets focus (eg; clicked on), onblur() will never be called.

Use the onfocus() event on these objects, bearing in mind that the script will be called every time the object recieves focus.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to onblur failing / not initiating
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11062 seconds with 13 queries