Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 683
  • Last Modified:

Anchor tag and Text field Focus

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
manas_sharma86
Asked:
manas_sharma86
  • 3
1 Solution
 
lpxtechCommented:
Add tabindex="1" to whichever element you would like the tab key to send you to first.
0
 
lpxtechCommented:
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
 
manas_sharma86Author Commented:
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
 
lpxtechCommented:
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now