I have a code block like the following:

$(document).ready(function(event) {
        $('#txtField').blur(function() {
                if (invalid(this.value))
                {
                        event.preventDefault();
                        //display error message
                }
        });
});

My purpose is to check for the input the users key-in and keep the
focus at the current text field if the input is invalid. But when I
jump to other fields by TAB or by mouse clicking, everything happens
as normal. Do you suggest any way to prevent the changing focus
action?
Indeed, the W3C DOM Event Specification states that *blur* event is
not cancelable, so I can understand why its default action cannot be
prevented. But how come when I try to view event.cancelable in
Firefox, it shows *true*?!
If I replace event.preventDefault() with $(this).focus(), it works in
IE, but not in Firefox.

Reply via email to