ScotDiddle Posted October 8, 2008 Share Posted October 8, 2008 Hi Folks, The excellent autoTab script from: From: http://javascript.internet.com/forms/auto-tab.htm works great, and is a time-saver for my users... This script sets focus to then next field when the maxlenth of the current field is hit by the user. I had to alter the script because some of the "next" fields may "still" be disabled because of the value entered for the "current" field. I found out how to bypass disabled fields from Google, and they all have the same basic format as my code posted below. My question, as seen in the code comments, is why does one need to worry about the form length and modulo ? modulo = inputIDXPlus6 % inputFormLength; (See below for full snippet...) Still trying to learn JS. Thanks for any input. Scot L. Diddle, Richmond VA if (input.id != 'HZ_CostGT500YN') { input.form[(getIndex(input)+1) % input.form.length].focus(); // Focus = current field + 1... } if (input.id == 'HZ_CostGT500YN') { if (mandatoryCostGT500) { input.form[(getIndex(input)+1) % input.form.length].focus(); // Focus = current field + 1... } else { // This meas getIndex(input)+1, +2, +3, +4 and +5 are disabled. // So, to avoid a javascript error, we need to bypass the disabled fields... input.form[(getIndex(input)+6) % input.form.length].focus(); /* Here's how it works... inputIDX = getIndex(input); alert('IDX ' + inputIDX); // 92 inputIDXPlus6 = getIndex(input)+6 alert('IDX + 6 ' + inputIDXPlus6); // 98 inputFormLength = input.form.length; alert('inputFormLength ' + inputFormLength); // 126 modulo = inputIDXPlus6 % inputFormLength; alert('modulo ' + modulo); // 98 formIDX = input.form[modulo]; alert('formIDX ' + formIDX) // object formID = formIDX.id alert('formID ' + formID); // HZ_PersonInjuryYN // Why the modulo? Why not use inputIDXPlus6? // // I tried it and with this example it worked... // // // This will also work: // // document.HZForm.HZ_PersonInjuryYN.focus(); */ } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.