AutoTab javascript function problem
<p>we've run into an issue with this while using it in our asp.net application. </p>

<p>The purpose of it is as follows:</p>

<ul>
<li>When in a textbox -> tab once MaxLength is reached</li>
<li>When in a checkbox -> tab once the control is toggled with the keyboard (spacebar)</li>
</ul>

<p>Asides from buttons, those are the only controls on the form. The function is toggled by the end user (saved by using a cookie). </p>

<p>Issues:</p>

<ul>
<li><p>As you'll notice, it goes about the process fairly randomly. Sometimes it performs quickly, sometimes it doesn't. The way we have the form set presently is with a very large tab index range that will more than likely remain. Not really worried about this issue to be honest, but nice if someone knows what to do.</p></li>
<li><p>Checkbox functionality is working very oddly. Say you have CheckBoxA and CheckBoxB. When you use the keyboard to toggle CheckBoxA, it grays out the box as though it were disabled and sets focus to CheckBoxB. At this point if you use the mouse and click anywhere on the document, it toggles CheckBoxA every time you click and ignoring normal mouse functionality for that area until you right click and then cancel the context menu. If you toggle CheckBoxB after it gains focus from AutoTab with the keyboard, CheckBoxA loses the disabled gray appearance (though it has never toggled) and the cycle repeats with CheckBoxB being the one with issues.</p></li>
</ul>

<p>Here is the code important to the function. CheckCookie() is a check to make sure that the user has AutoTab set otherwise AutoTab doesn't happen. Array.contains goes through the array to find if the keycode entered is present in it.</p>

<pre><code>function test(input, inputClientID, e) {
if (checkCookie()) {
    var acceptedChars = ["48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "96", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "186", "187", "188", "189", "190", "191", "192", "219", "220", "221", "222"];
    if (input.type == "text") {
        len = document.getElementById(inputClientID).getAttribute("MaxLength");
        curLen = document.getElementById(inputClientID).getAttribute("Value");
        if ((len != null) &amp;&amp; (len != "") &amp;&amp; (curLen != null) &amp;&amp; (curLen != "")) {
            if (len &lt;= curLen.length) {
                var keycode;
                if (window.event) keycode = window.event.keyCode;


                if (e.shiftKey == true &amp;&amp; keycode == 9) {
                    return;
                }
                else if (acceptedChars.contains(keycode)) { //(e.shiftKey == false &amp;&amp; keycode != 9)
                    tabNextCtrl(input);
                }
            }
        }
    }
    else if (input.type == null) {
        if (input.firstChild.type == "checkbox") {
            var keycode;
            if (window.event) keycode = window.event.keyCode;

            if (keycode == 32) {

                //if (input.firstChild.checked) {
                //    input.firstChild.checked = false;
                //}
                //else {
                //    input.firstChild.checked = true;
                //}
                tabNextCtrl(input.firstChild);                    
            }
        }
    }
}}
</code></pre>

<p>The tabbing is done using a sort here (and where the bottleneck of issue #2 comes in I believe):</p>

<pre><code>function tabNextCtrl(input) {
var tbIndex = input;
var aIndex = 99999999;

for (i = 0; i &lt; input.form.elements.length; i++) {
    if ((input.form.elements[i].tabIndex &gt; input.tabIndex) &amp;&amp; (input.form.elements[i].tabIndex &lt; aIndex)) {
        aIndex = input.form.elements[i].tabIndex;
        tbIndex = input.form.elements[i];
    }
}
tbIndex.focus();
}
</code></pre>

<p>I apologize as this is very lengthy (the issue isn't something I know of having a common name, though I've seen the behavior before), but any assistance you can give with this issue would be very appreciated.</p>

<p>Thanks,</p>
