Solved

Anchor tag and Text field Focus

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

<html>


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

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

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?

0
Comment
Question by:manas_sharma86
[X]
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
4 Comments
 
LVL 6

Expert Comment

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

Expert Comment

by:lpxtech
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

0
 

Author Comment

by:manas_sharma86
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?
0
 
LVL 6

Accepted Solution

by:
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.
disableTab(document.getElementsByTagName("input"));
disableTab(document.getElementsByTagName("a"));
function disableTab(elms) {
	for (var i = 0; i < elms.length; i++) {
		elms[i].tabIndex="-1";
	}
}

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

733 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