[thelist] Javascript text field onfocus

jsWalter jsWalter at torres.ws
Tue Jun 22 18:15:35 CDT 2004

2 things...

1) your method does not take into account multiple FORMs on single page.
   Yes, I know, but I've seen to too many times.

2) Determining "state" of an object is not all that straight forward.

   "walking" up the DOM tree and looking at the DISPLAY value works
   but *only* if the value was set via HTML inline or JS code.

   To see what the CSS characteristics are is a bit hairier.

Below is my rendition of your "requirements" minus the DISPLAY checking.

We'll see if anyone has any good ideas on how to solve that pickle.

Meanwhile I'll see what my little brain can think of.

This is an interesting issue, I'd love to have a solution as well.



// WARNING: If you already have an onLoad call, you need to
//          incorporate that into this as well.
window.onload = function()
	// Boolean to check if we found our first TEXT Object
	var bolFound = false;

	// Build array of all FORMS on this page
	var colForms = document.forms;

	// There may be more than one (1) Form on a page
	// Loop through them all
	for (var i = 0; i < colForms.length; i++)
		// Send current From for further processing

		// If a TEXT Object is already hit
		if ( bolFound )
	}	// for (...)

	// Form Processor
	function InitForms(objForm)
		// Create collection of FORM Elements
		var arryInput = objForm.getElementsByTagName('input');

		// Loop through all the Objects in the given Form
		for (var i = 0; i < arryInput.length; i++)
			// Get the current FORM Element
			objElement = arryInput[i];

			// Only look at the TEXT Object
objElement.getAttribute("type").toLowerCase() == "text" )
				// Place focus here

				// Since we found it
				bolFound = true;

				// We can leave now
			}	// if( ... )
		}	// for (...)
	}	// function InitForms(objForm)
}	// window.onload = function()


More information about the thelist mailing list