Select field with javascript (no value)

1

Good to all I would like that when loading a page with its form, a certain text field is selected without having to click on it, this in order to try to avoid using the mouse, I have googled but in everywhere comes the typical document.getElementByID.value () and that is to select the value, I just want to select the field when loading the page, as if we click on it, thank you very much

    
asked by SabanaSabrosa 26.01.2018 в 16:14
source

2 answers

3

You have to use the .focus () function

document.getElementById("mytext").focus();
    
answered by 26.01.2018 в 16:18
1

Property autofocus of the% tag input

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

HTML Input autofocus Attribute

    
answered by 26.01.2018 в 17:38