I need this field to be focused when the user opens the page. I don't know if it changes anything but it's inside a modal window I load from a PHP file.
Is there an easy way to do it?
Definition and Usage The autofocus attribute is a boolean attribute. When present, it specifies that an <input> element should automatically get focus when the page loads.
We used the focus() method to focus the input field in the handleClick function. The current property on the ref gives us access to the input element, so calling ref. current. focus() sets the focus on the input.
Input Text focus() Method The focus() method is used to give focus to a text field. Tip: Use the blur() method to remove focus from a text field.
Using JavaScript, you can achieve this:
document.onload = function() {
document.getElementById("question-box-0").focus();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With