Anchor tag and Text field Focus

Posted on 2008-11-01
Last Modified: 2012-05-05
I have a html file :


 <script type="text/javascript" src="keyboard.js" charset="UTF-8"></script>

<input type="text">
<a href="#">FIRST</a><br>
<a href="#">SECOND</a><br>
<a href="#">THIRD</a><br>
<a href="#">FOURTH</a>

and a JS file as well...

Now my question is that when i press tab on the browser it straight away heads to the text field...

I wan't that it should focus straight on the anchor tag instead of the text field..

How is it possible?

Question by:manas_sharma86
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

ID: 22855955
Add tabindex="1" to whichever element you would like the tab key to send you to first.

Expert Comment

ID: 22855958
Here is an example.
<input type="text" name="test"/>
<a href="#test" tabindex="1">Test</a>
<input type="text" name="test2" tabindex="3" />
<input type="text" name="test3" />
<a href="#test2" tabindex="2">Test 2</a>

Open in new window


Author Comment

ID: 22855990
Cool...And if i don't wan't the browser to react to the tab key..Is that possible...

As in if i press tab...then nothing happens?

Accepted Solution

lpxtech earned 500 total points
ID: 22856021
I don't think it's possible to have no reaction to the tab key all together. Althought, you can prevent an tabindex's within the web page using tabindex="-1"

You could use a javascript function to loop through all of the elements you want to disable also and add the tabindex="-1" on page load, but it only works in IE, code is below.
function disableTab(elms) {
	for (var i = 0; i < elms.length; i++) {

Open in new window


Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question