I am trying different code suggestions to change the focus to another field instead of text field using jQuery:


and changing the focus on load:

<script>function setingFocusOnLoadFocus() {}</script>

But none of them seem to work. The focus goes to the field which I am trying to set. but after a second it then changes over to the text field.

I have tried using window.onload, and it works too. But it breaks the dependent picklist on the page. (As depedent picklist is not getting populated load when we use window.onload)

Is there any other way to achieve this?

  • why don't use tabindex="1" property on your input field. Mar 24, 2017 at 6:33
  • @RohitMourya I have tried that, unfortunately it is not working either.
    – Devendra
    Mar 24, 2017 at 6:41
  • have you tried $document.ready or may be if you could just post your code. Mar 24, 2017 at 6:49

1 Answer 1


The standard library automatically selects the first field for you. The only way to guarantee that you will "beat" the built-in logic is to use asynchronous code:

window.addEventListener("load", function() {
    setTimeout(function() {
        document.querySelector(".elementId").focus(); //do something
    }, 100);  // 0.1 seconds after load time.
  • This solution got worked. Thank you @sfdcfox for your help :)
    – Devendra
    Mar 24, 2017 at 23:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .