[thelist] JavaScript focus & getElementByID

.jeff jeff at members.evolt.org
Wed Jan 15 11:41:06 CST 2003


martyn,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Martyn Haigh
>
> function getObj(name)
> {
>   if (document.getElementById)
>   {
>   	this.obj = document.getElementById(name);
> 	this.style = document.getElementById(name).style;
>   }
>   else if (document.all)
>   {
> 	this.obj = document.all[name];
> 	this.style = document.all[name].style;
>   }
>   else if (document.layers)
>   {
>    	this.obj = document.layers[name];
>    	this.style = document.layers[name];
>   }
> }
>
> I have this input element
> <input type="checkbox" id="KnowMore" name="KnowMore"
>  value="True" />
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

no offense, but you really should resist the urge to use the id to access
form elements.  the elements array in combination with the name attribute
has much better support.

however, in cases where you're working with other tags, your method is quite
nice.

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/




More information about the thelist mailing list