[thelist] detecting form fields in JS
Joe Crawford
artlung at artlung.com
Sun Dec 10 23:11:35 CST 2000
On Mon, 11 Dec 2000, Matthew Walker wrote:
> How do I detect whether or not a form element exists?
>
> e.g. how do I adapt this script to not give an error if there is no form on
> the page?
>
> <body onload="document.forms[0].elements[0].focus();">
Haven't tested this - but probably:
<body onload="if (document.forms[0].elements[0])
document.forms[0].elements[0].focus();">
would do it. You check to see if there's at least one form and if
there's a first element to focus on.
Theoretically should work,
Joe
-
Joe Crawford <mailto:joe at artlung.com>
* I am a Web Designer and Developer;
* Find out about me at : http://www.ArtLung.com
* A Mailing List for San Diego Web Folks : http://WebSanDiego.org
More information about the thelist
mailing list