/    Sign up×
Community /Pin to ProfileBookmark

onblur failing / not initiating

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);”>[/code]

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.’);
}
}
}
[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliApr 04.2008 — 
What I'm finding is that if the click used to initiate the onblur() used like &lt;input type="text" id="qty" name="qty" value="" onblur="makeRequest('ajax_insert.php?field_name=qty&amp;field_value=',this.value);"&gt; 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 straight for the submit button before clicking anywhere else.
[/quote]
As soon as a form is submitted, the content of the document (including scripts) is unloaded.

If your request has to happen immediately prior to a form submission, you could try calling it within the form's onsubmit handler.
Copy linkTweet thisAlerts:
@cesarcesarauthorApr 05.2008 — the call needs to be on the blur of the textfield.

Is there any way to load all script before they are unloaded?
Copy linkTweet thisAlerts:
@Logic_AliApr 05.2008 — the call needs to be on the blur of the textfield.

Is there any way to load all script before they are unloaded?[/quote]
If you mean the call to take place immediately prior to a form submission then yes - as I explained. You could do something similar for any links that may be clicked, but you need to clarify exactly what's going on.
Copy linkTweet thisAlerts:
@cesarcesarauthorApr 07.2008 — If you mean the call to take place immediately prior to a form submission then yes - as I explained. You could do something similar for any links that may be clicked, but you need to clarify exactly what's going on.[/QUOTE]

My form has multiple inputs with the same onblur(). how would I call just the most recent left field to blur?
×

Success!

Help @cesarcesar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...