Jump to content

Bypass Disabled Fields for next .focus()


ScotDiddle

Recommended Posts

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();

					*/

				}

			}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.