Solved

Anchor tag and Text field Focus

Posted on 2008-11-01
4
647 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

776 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