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.
Author by
user502052
Updated on June 04, 2022Comments
-
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?
-
Eric Fortis over 13 yearsusing jQuery $('#btnId').focus()
-
Pini Cheyni over 7 yearsusing angular and Angular-Material design, you need to use md-autofocus. There is a very good explanation here : material.angularjs.org/1.0.4/api/directive/mdAutofocus
-
-
user502052 over 13 yearsI tried that but it does not work. Maybe I have to use some JavaScript... so, it will work with all browsers?
-
Jubayer Arefin over 7 yearsJust to clarify, by "#Button Two" I meant the button element's ID.
focus()
can also be used to focus on text input etc.