11

Here is my code:

jQuery('#reporter').blur(function() {
            if(data.indexOf('['+jQuery('#reporter').val()+']') >= 0)
            {
                alert("Please do not select pseudo user as Reporter");
                jQuery('#reporter').focus();                    
            }               
        });

In IE, the cursor is not blinking in the "reporter" element. In Chrome, it is.

Thanks a lot!

Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112
chintu
  • 185
  • 1
  • 3
  • 14
  • 1
    Are we to assume reporter is a ` – SliverNinja - MSFT Nov 03 '11 at 14:32
  • Not the problem, but: Note that *every time* you call `jQuery('#reporter')` jQuery has to go off and do that. Within the `blur` handler, you could do `var $this = $(this);` at the top and then use `$this` rather than `jQuery('#reporter')`, saving a bit of trouble and verbosity. – T.J. Crowder Nov 03 '11 at 14:32
  • this has been answered already here: http://stackoverflow.com/questions/1326993/jquery-focus-sometimes-not-working-in-ie8 – andrew Nov 03 '11 at 14:33

1 Answers1

18

You'll need to set the blur later by using a timeout. The other control might execute focus first.

Suggestion

window.setTimeout(function(){
   $('#reporter').focus();
}, 50);

This gives IE the time to focus the other control, steal the focus and then add it to #reporter.

Prevent action

$('#reporter').blur(function(e) {
    if(data.indexOf('[' + jQuery('#reporter').val() + ']') >= 0) {
        alert("Please do not select pseudo user as Reporter");
        $('#reporter').focus();
        e.preventDefault();
    }
});
Kees C. Bakker
  • 32,294
  • 27
  • 115
  • 203