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,
robrodpAsked:
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.

GaryCommented:
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?

document.getElementById("element_id").focus();
0
robrodpAuthor Commented:
It is a simple hashtag;

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

It takes to the beginning of the page
0
GaryCommented:
http://jsfiddle.net/GaryC123/cdgRd/1/

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

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!!!
0
robrodpAuthor Commented:
Thx for great code
0
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
HTML

From novice to tech pro — start learning today.