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,750
  • 2
  • 30
  • 39
Prashant Shilimkar
  • 8,402
  • 13
  • 54
  • 89

1 Answers1

0
function myFunction()
{
   document.getElementById('city').focus()
}
Govind Singh
  • 15,282
  • 14
  • 72
  • 106