A closure! Actually, I don't even know what the heck a closure is. I mean, I understand intellectually, but ask me to write one or explain it back and I will fail. But apparently this is one.
The reason to use this technique (and I agree, it should be used wisely) is when you have a field called "choose username" and when you blur from it, it erases your choice, and gives a little red error saying, "Sorry that username is taken, try again." and focuses back on the field. I have a case for no value which lets blur happen normally. Man, programming is hard. Thank god I have jQuery so I can avoid it most of the time. Feature request for jQuery: Blur should have a callback function. Like slideUp. Why doesn't everything have a callback? Glen On 5/24/07, Karl Rudd <[EMAIL PROTECTED]> wrote:
If you're wanting the text field to retain focus no matter what then you should probably reconsider. It's not a very good thing from a UI design perspective. It is possible but it pretty much "locks up" the entire browser. Having given you the "don't shoot yourself or the user in the foot" warning, here's code to do it: $('input#MyTextInput').blur( function() { var input = this; setTimeout( function() { input.focus(); }, 0); }); Tested and working in IE and Firefox. Karl Rudd On 5/25/07, Glen Lipka <[EMAIL PROTECTED]> wrote: > Code sample: > $("input#MyTextInput").blur( > function() { > setTimeout("$('#MyTextInput').focus()",0); > } > ); > > That works in FF. > ---------------------- > $("input#MyTextInput").blur( > function() { > $('#MyTextInput').focus(); > } > ); > > That does not work in FF. > --------------------- > > Trying to re-focus back on an input after a blur event. > IE works in more circumstances, but FF does not. > > Is there an easier way? > > Glen >