Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set tab order in jquery

Tags:

jquery

I'm using Telerik controls, specifically the numerical textbox where you can set a up-down arrow to increment/decrement values in a textbox. I am required to set the tab order to move to the next field but since there's a button on the up-down arrow, the browser will go through those buttons first then move to the next textbox field.

How do you set the jquery to detect the next visible textbox/dropdown/etc input field and move to that on pressing the tab button instead of running through the buttons near it?

like image 418
Martin Ongtangco Avatar asked May 24 '10 03:05

Martin Ongtangco


3 Answers

$(function() {
  var tabindex = 1;
  $('input,select').each(function() {
     if (this.type != "hidden") {
       var $input = $(this);
       $input.attr("tabindex", tabindex);
       tabindex++;
     }
  });
});
like image 54
Vikas Avatar answered Sep 20 '22 20:09

Vikas


You actually set this with the HTML attribute tabindex ordered ascending numerically for all inputs on the page. So to skip the buttons, start with the first input on the page assigning it tabindex=1, the second tabindex=2, setting subsequent inputs accordingly. When you get to the buttons that you want to skip simply don't give them a tabindex value, or give them indices at the end of the list.

like image 35
mVChr Avatar answered Sep 17 '22 20:09

mVChr


You can also try this

$('input,select :visible').each(function (i) { $(this).attr('tabindex', i + 1); });
like image 31
Gautam Avatar answered Sep 21 '22 20:09

Gautam