简体   繁体   中英

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

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

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).

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?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM