...

View Full Version : tabindex auto jump



angiras
10-27-2003, 09:42 AM
this code works only with tabindex = 1,2,3

--------------------------------------------------

<script type="text/javascript">
function toUnicode(elmnt,content)
{
if (content.length==elmnt.maxLength)
{
next=elmnt.tabIndex
if (next<document.forms[0].elements.length)
{
document.forms[0].elements[next].focus()
}
}
}
</script>


<input size="2" tabindex="1" id="one"
maxlength="2" onkeyup="toUnicode(this,this.value)" />

<input size="2" tabindex="2" id="two"
maxlength="2" onkeyup="toUnicode(this,this.value)" />

<input size="2" tabindex="3" id="three"
maxlength="2" onkeyup="toUnicode(this,this.value)" />

-----------------------------------
if I use tabindex = 100,101,102 it doesn't work

glenngv
10-27-2003, 10:00 AM
It is because you are accessing the next field by its position in the form. If you use 1, 2, 3 the position is correct but if you use 101, 102, obviously it does not correspond to the position of the field in the form.

try:



function toUnicode(elmnt)
{
var next;
if (elmnt.value.length==elmnt.maxLength)
{
next=elmnt.tabIndex + 1;
//look for the fields with the next tabIndex
var f = elmnt.form;
for (var i = 0; i < f.elements.length; i++)
{
if (next<=f.elements[i].tabIndex)
{
f.elements[i].focus();
break;
}
}
}
}
...
<input size="2" tabindex="1" id="one" maxlength="2" onkeyup="toUnicode(this)" />

angiras
10-27-2003, 10:07 AM
.... it works !

thankX :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum