Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
onblur failing / not initiating
Old 04-04-2008, 06:08 PM onblur failing / not initiating
Extreme Talker

Posts: 196
Trades: 0
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
 
 
Register now for full access!
Old 04-05-2008, 05:58 AM Re: onblur failing / not initiating
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to onblur failing / not initiating
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.09605 seconds with 12 queries