[Javascript] Accessing form name
Nick Fitzsimons
nick at nickfitz.co.uk
Mon Nov 21 07:22:47 CST 2005
> function resetForm() {
> var theForm = document.getElementsByTagName('form');
> var formName = theForm.name;
> alert(formName);
>
> document.formName.reset();
> }
>
> This does get the form but name is returned as undefined. Where am I
> going wrong or is there a simpler/better way to do this? Thank you.
>
Actually, getElementsByTagName returns a NodeList, which doesn't have a
name. Treat it like an array:
var allForms = document.getElementsByTagName("form");
var theFirstForm = allForms[0];
alert(theFirstForm.name);
HTH,
Nick.
--
Nick Fitzsimons
http://www.nickfitz.co.uk/
More information about the Javascript
mailing list