[Javascript] Accessing form name
Schalk
schalk at volume4.com
Mon Nov 21 06:59:42 CST 2005
diego nunes wrote:
>On 21/11/05, Schalk <schalk at volume4.com> wrote:
>
>
>>What is the best way to obtain a form name if it is not possible to pass
>>it into the script as such: formFunction(this);
>>
>>
>
> You want the "name", having the instance of the form, or wanna get
>the instance, based onde the "name"?
>
> 1) instance named "formInstance":
> alert(formInstance.name);
>
> 2) form named "formanswer":
> alert(document.forms['formanswer']);
> or, better, if you have an unique ID:
> alert(document.getElementById('formanswer'));
>
> Amplexos.
>
>
Thanks Amplexos.
But here is my problem:
I want to create a simple generic reset function for forms within
Joomla. Now, I do not know beforehand what the form name or id is and
therefore wanted to determine this with JavaScript. Here is what I have
so far:
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.
--
Kind Regards
Schalk Neethling
Web Developer.Designer.Programmer.President
Volume4.Business.Solution.Developers
More information about the Javascript
mailing list