Reputation: 10226
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
Upvotes: 0
Views: 241
Reputation: 281405
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?)
Upvotes: 2
Reputation: 449395
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).
Upvotes: 1