Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter text field focus order with jQuery

I was wondering, if I have text fields displayed so, could I alter the order in which the focus using javascript (preferably jQuery).

See this example here.

What I mean that when you tab around them, instead on going "one, two, three, four, five" force them to go: "one, two, four, three, five".

Thanks in advance!!

EDIT: Thanks to all, I didn´t know it was possible with HTML only. Of course if this is the case I´ll go with that.

BTW Thanks to all your answers!!! (I`ll upvote the complete ones) but will accept the first one.

like image 292
Trufa Avatar asked Dec 23 '10 21:12

Trufa


3 Answers

No need for jQuery! Check out tabIndex.

like image 50
matthewwithanm Avatar answered Oct 16 '22 22:10

matthewwithanm


Set the tabindex attribute on the elements.

jsfiddle

like image 25
Shurdoof Avatar answered Oct 16 '22 20:10

Shurdoof


You can use the tabIndex property to have the order of tabbing as needed: e.g.:

<input type="text" tabIndex=1 value="one"/><br />
<input type="text" tabIndex=2 value="two"/>
<input type="text" tabIndex=4 value="three"/><br />
<input type="text" tabIndex=3 value="four"/>
<input type="text" tabIndex=5 value="five"/>

But if you want to dynamically change the tabbing at client side, you can use jQuery .attr function.

$(<YOUR ELEMENT SELECTOR>).attr("tabIndex", "YOUR_VALUE");
like image 44
Chandu Avatar answered Oct 16 '22 20:10

Chandu