set focus on a text form field html

My html page has a form and towards the end there is a link that takes the page to an anchor near the top of the form.

Is there a way when I click on the link the focus is set on the text field. Remember the page does not reload. It just goes to the top of the page,
Who is Participating?
GaryConnect With a Mentor Commented:

<a href="#" onclick='location.hash="#forma";document.getElementById("mytextbox").focus();'>

Open in new window

If the hash tag is at the same level as the input you could drop the location.hash bit.
You can use this - just change the ID to the id of the element. Without code I cannot advise how/where you implement it. Is the anchor just a standard hash tag link?

robrodpAuthor Commented:
It is a simple hashtag;

<a href="#forma">llena la forma de contacto</a>

It takes to the beginning of the page
robrodpAuthor Commented:
Just right!!!
robrodpAuthor Commented:
Thx for great code
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.