0

In My Application i m using RichTextEditor on a form with some other fields. I set focus on first text box like this

$("#tofield").focus();

But as RichTextBox is taking some time to load, so when RichTextBox loading complete focus removed from first text box.

I searched on it and found some suggestions to use setTimeout

 setTimeout(function () {
        $("#tofield").focus();
    }, 1000);

but it is also not working

focus() is only working in FF not in Chrome and IE

Any suggestions..

Anil D
  • 1,989
  • 6
  • 29
  • 60

4 Answers4

0

Try this code

$('#tofield').focusout(function() {
    setTimeout(function() {
        $(this).focus();
    }, 0);
});
Sankar
  • 652
  • 6
  • 13
0

If it is taking time to load you can try with this

        $( window ).load(function() {
            $("#tofield").focus();
        });
0

Just want to share how i fixed this...

Not sure how and why it is working but it did the trick

I just added following line of code before TextBox

<input type="button" id="btntofieldfocus" style="width:0px;height:0px !important;padding: 0 0 0 0 !important;position:absolute;left:-50px;" value="" onclick="javascript:document.getElementById('tofield').focus()" />

May help others...

Anil D
  • 1,989
  • 6
  • 29
  • 60
0

you should use

$(document).ready(function(e){
    $("#tofield").focus();
});
Sohil Desai
  • 2,940
  • 5
  • 23
  • 35