Forum Moderators: open

Message Too Old, No Replies

Refering to a Form without Name attribute

can not use name with xhtml strict

         

chadmg

8:10 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



XHTML Strict does not have a name attribute for the form tag. I have always refered to a form in javascript by using document.formname. Since I no longer have a name attribute, how do I refer to the form? I can not use document.forms[0] either, since with server side includes I may not know how many forms are on the page. XHTML does allow the id attribute, but I do not know how to use that to access the form. What is the best cross-browser way to refer to a specific form in javascript without the name attribute?

chadmg

8:36 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



I guess I should have just spent an extra minute to run a test before I asked the question. I just thought that the below only worked if formname was set by the name attribute. Guess I was wrong. If anyone else would like to know...

<form id="formname">
javascript: document.forms['formname']

works just fine. :)

Birdman

9:25 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or, you can use this:

document.forms[0]

Assuming that is the first, or only, form on the page. If there were multiple forms, you just increment the zero(0) accordingly.

Birdman