[thelist] JavaScript focus & getElementByID

Martyn Haigh martyn.haigh at virgincosmetics.com
Thu Jan 16 03:08:01 CST 2003


<snip>
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.
</snip>

Jeff - no offense taken - I'm rubbish at Javascript!  Could you explain what
is wrong with using this approach to access form elements?

How would you do it so that it was cross browser?

Cheers

Martyn Haigh

Site Developer

-- original message --

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> 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" />
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><



DISCLAIMER: The information in this email is confidential and may be legally
privileged. It is intended solely for the addressee. Access to this email by
anyone else is unauthorised. If you are not the intended recipient, any
disclosure, copying, distribution or any action taken or omitted to be taken
in reliance on it, is prohibited and may be unlawful.





More information about the thelist mailing list