Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preselect text input on page load

I don't want the user to have to click the first text box to write on it. When the page is loaded, I want the text input to be preselected.

like image 623
juancrrn Avatar asked Dec 20 '22 21:12

juancrrn


1 Answers

Use the autofocus attribute inside your html element.

In this example, you can see the "First name" input has autofocus, and it will be automatically selected when the page loads, so the user can type straight away:

<!DOCTYPE html>
<html>
<body>

<form action="demo_form.asp">
  First name: <input type="text" name="fname" autofocus><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit">
</form>

</body>
</html>

The autofocus attribute, of the input tag, is not supported in Internet Explorer 9 and earlier versions.

like image 183
Jero Franzani Avatar answered Dec 28 '22 08:12

Jero Franzani