views:

57

answers:

2

How do I get the name of a form in Javascript?

I have tried stuff like:

document.forms[0].name
document.forms[0].id //I have both name and id set
+1  A: 

Strange. Should both work.

Are you 100% sure you have no other form(s) in the document? Does

document.getElementById('form_id').name

work? (form_id being the ID you assigned).

Pekka
If I do that then I already know the name/id of the form. There is only 1 form.
Josh Curren
+1  A: 

document.forms[0].name works for me in both IE7 and FF3.5... I guess there must be some other problem.

(Are you trying to access the name from a <script> element at the top of the HTML, before the form has appeared?)

RichieHindle
+1 good thought.
Pekka