Links

Home
Open Source
World News
About W3 Systems
References
C++ Reference
CSS
MySQL
SEO
Meta-Site
C++ Tutorial
Quirks Mode
Bug Collection
Detecting The World
Free CSharp
Javascript Reference
Meta-Site
ASCII Table
Network Engineering
DHTML DOM
SSL
Staff
Rainbow Custom Logo Mats
Primes
Spellchecking
PDF Conversion
Sabbaticals
XML
Health Sharing
Household Rules for
daughters male visitors

DHTML DOM References


Setting Focus.

The following function is a lifesaver.
It's an automatic usability enhancement for forms.
 It insures that focus is set on the first valid control.
Just call it from the onload event. 
function focusFirstControl( formID )
{
var frm = document.forms[formID];
if( frm )
{
// iterate throuugh form controls, find the first usable one to focus.
for(i in frm.elements)
{
if( frm.elements[i] && frm.elements[i].tagName )
{
var tagName = frm.elements[i].tagName;
if( tagName == "SELECT" || tagName == "INPUT" && frm.elements[i].type == "text" || tagName == "TEXTAREA" )
{
if( tagName == "INPUT" && frm.elements[i].readOnly )// check readonly property
continue;
if( frm.elements[i].disabled ) // is it disabled
continue;
if( frm.elements[i].offsetWidth == 0 ) // best visibility indicator I could find
continue;
frm.elements[i].focus();
break;
}
}
}
}
}  
 
 
 

http://www.mozilla.org/docs/dom/domref/dom_shortTOC.html
Copyright (C) 2008 - W3 Systems Design