How to set focus on form with more of one button?

11,211

Solution 1

$(document).ready(function() {
  $("#Button Two").focus();
});

Solution 2

Set tabindex to the second button less than the first one.

EDIT

yes, you can use javascript, document.getElementById("button2").focus();. Make sure you add this code on page load.

Share:
11,211
user502052
Author by

user502052

Updated on June 04, 2022

Comments

  • user502052
    user502052 almost 2 years

    I have two buttons for the same form. In the HTML code I declared first the "Button One" and after the "Button Two".

    When I display the form, the focus is on the "Button One", but I would like to have it on the other one without change them the screen position.

    What I can do?

  • user502052
    user502052 over 13 years
    I tried that but it does not work. Maybe I have to use some JavaScript... so, it will work with all browsers?
  • Jubayer Arefin
    Jubayer Arefin over 7 years
    Just to clarify, by "#Button Two" I meant the button element's ID. focus() can also be used to focus on text input etc.