Monday, October 25, 2010

Automatically advance tab position

Below function is to automatically advance tab position from current text control to another text control as soon as soon as current textbox gets filled.

In below function

fromId : id of current text box
fromLen : length of current textBox
toId : id of target textBox

function autoAdvance(fromId, fromLen, toId, evt)
{
var textBox = document.getElementById(fromId);
var charCode = (evt.which) ? evt.which : event.keyCode;
len = textBox.value.length;
if (len == fromLen && ((charCode >= 48 && charCode <= 57) || (charCode >= 96 && charCode <= 105)))
{
document.getElementById(toId).focus();
}
}

Call this function on onKeyUp event of text box.

No comments:

Post a Comment