Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
194
rated 0 times [  198] [ 4]  / answers: 1 / hits: 20710  / 14 Years ago, mon, november 15, 2010, 12:00:00

I want to set up an onBlur event for an input element that validates the value and, if invalid, cancels the blur and refocusses the input. However returning false from onBlur does not cancel the onBlur the way it does with onClick. Is there a solution for this (perhaps using jQuery?)


More From » jquery

 Answers
21

I don't know of any reliable cross-browser way to do this. Usually setting a small timeout in the onblur event and calling focus() when the timer fires works.



For example:



document.getElementById('your_input_id').onblur = function() {
var self = this;
setTimeout(function() { self.focus(); }, 10);
}

[#94956] Friday, November 12, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
braydon

Total Points: 0
Total Questions: 102
Total Answers: 111

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
braydon questions
Tue, Nov 23, 21, 00:00, 3 Years ago
Mon, Dec 21, 20, 00:00, 4 Years ago
Fri, May 15, 20, 00:00, 4 Years ago
Fri, Mar 27, 20, 00:00, 4 Years ago
;