Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Accessing form name
- From: rer at datacompusa.com (Roger Roelofs)
- Subject: [Javascript] Accessing form name
- Date: Mon Nov 21 07:20:47 2005
Shalk,
On Nov 21, 2005, at 7:59 AM, Schalk wrote:
>> On 21/11/05, Schalk <schalk@xxxxxxxxxxx> wrote:
> 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.
getElementsByTagName returns an array of form objects. So, if you
know for a fact that there will only be one form on the page you
could write it like this.
function resetForm() {
var theForm = document.getElementsByTagName('form')[0];
var formName = theForm.name;
alert(formName);
document.formName.reset();
}
However, I don't recommend this approach because invariably someone
else changes the html and the javascript 'breaks'. If you could give
us a little more info about what you are trying to accomplish and
what triggers the need for the reset we could provide better advice.
Roger
-------------------------------------------------------
Roger Roelofs web www.datacompusa.com
Datacomp Appraisal Services Email rer@xxxxxxxxxxxxxxx
3215 Eaglecrest Drive, NE
Grand Rapids, MI 49525-4593
- References:
- [Javascript] Accessing form name
- From: Schalk
- [Javascript] Accessing form name
- From: diego nunes
- [Javascript] Accessing form name
- From: Schalk
- [Javascript] Accessing form name
- Prev by Date: [Javascript] Accessing form name
- Next by Date: [Javascript] Accessing form name
- Previous by thread: [Javascript] Accessing form name
- Next by thread: [Javascript] Accessing form name
- Index(es):