Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] Accessing form name


  • From: nick at nickfitz.co.uk (Nick Fitzsimons)
  • Subject: [Javascript] Accessing form name
  • Date: Mon Nov 21 07:28:39 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/