0

In an HTML file, I have a text field and a button. When the button is pressed, text is added to the to text field via plain JavaScript.

HTML:

please input : <input id="city" type="text" name="city" />
<button onclick="myFunction()">click</button>

JavaScript:

function myFunction()
{
   var a=document.getElementById("city").value ;
   document.getElementById("city").value = a;
}

How to set the focus of the text field to the last entered character by using only plain JavaScript, without jQuery or other libraries?

Thank you in advance.

Teemu Leisti
  • 3,711
  • 2
  • 29
  • 37
Prashant Shilimkar
  • 7,816
  • 12
  • 49
  • 85

1 Answers1

0
function myFunction()
{
   document.getElementById('city').focus()
}
Govind Singh
  • 14,768
  • 13
  • 67
  • 100