Hi,
I'm somewhat familiar with JS but I have a problem I can't solve. I have an "auto tab" function that will automatically tab to the next tabindex value. I do this because the fields aren't necessarily in any logical order and I don't want to hard code the next field because it could very well change in the future.
The function works fine on small pages with a dozen or so fields, however, I have some pages that are quite large and if you look at my code you see that I'm searching the entire page which makes it very slow. Are there any better solutions? Thanks, 61
function tab(current, n){
var obj = null;
for (var i=0; i < document.phone.elements.length; i++) {
obj = document.forms[0].elements;
if (obj.getAttribute("tabindex") == (current.getAttribute("tabindex") + 1))
if (current.getAttribute && current.value.length == n)
obj.focus();
}
}
<form>
<input type="text" name="first" size=4 onKeyup="tab(this, 3)" tabindex=1>
<input type="text" name="second" size=4 onKeyup="tab(this, 3)" tabindex=2>
</form>
I'm somewhat familiar with JS but I have a problem I can't solve. I have an "auto tab" function that will automatically tab to the next tabindex value. I do this because the fields aren't necessarily in any logical order and I don't want to hard code the next field because it could very well change in the future.
The function works fine on small pages with a dozen or so fields, however, I have some pages that are quite large and if you look at my code you see that I'm searching the entire page which makes it very slow. Are there any better solutions? Thanks, 61
function tab(current, n){
var obj = null;
for (var i=0; i < document.phone.elements.length; i++) {
obj = document.forms[0].elements;
if (obj.getAttribute("tabindex") == (current.getAttribute("tabindex") + 1))
if (current.getAttribute && current.value.length == n)
obj.focus();
}
}
<form>
<input type="text" name="first" size=4 onKeyup="tab(this, 3)" tabindex=1>
<input type="text" name="second" size=4 onKeyup="tab(this, 3)" tabindex=2>
</form>