user1739140
user1739140

Reputation: 211

Reuse of html element ids?

I have a page with three different forms. The second has to have access to the post vars submitted by the first. The third has to have the cumulative post vars.

Even though an element such as a hidden field has the same id as another form element, it should be valid if it exists under a different form element, right? I have done this in the past without problem as far as submission processing, but the xhtml doctype syntax checker in my text editor (BBedit on Mac OSX) marks the re occurrence of an element id as an error.

To be completely valid with respect to doctype I have to use xhtml transitional to allow name attributes (forms won't submit with out them)

I don't want to have three different sets of hidden fields to transmit the same values for each different form That requires huge amounts of redundant processing on the server side.

Thanks for reminding me that I can use the same name attribute and different ids. Sometimes I get wrapped up in details and loose sight of the bigger picture

By the way, I posted a problem with using one form for the entire setup at: https://stackoverflow.com/questions/21315920/browser-caching-post-vars and I have not received any definitive answer there.

Upvotes: 0

Views: 115

Answers (1)

Andrew Moore
Andrew Moore

Reputation: 95344

The id attribute MUST be unique per document. However, if you simply want various fields to accessible using the same key server-side, simply set the name attribute. name has no such requirement and can differ from the id.

Upvotes: 3

Related Questions