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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

<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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robrodpAuthor Commented:
Just right!!!
robrodpAuthor Commented:
Thx for great code
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.