Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

More than one form input element with same name

 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know what happens if more than one element (such as <INPUT> has the same name, in the same form?
It does not seem to be mentioned in specs or books. I guess that it is perhaps implicit that names are supposed to be unique. But can anyone point me to documentation that says so?
I just wondered if there might be tricks available if using the same name more than once weren't illegal. Compare, perhaps, to the useful possibilities of more than one Submit button per form, which is a fairly well-used trick.
 
Sheriff
Posts: 67641
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While I can't cite any specification on the subject, using the same name is most certainly legal -- it is, in fact, the best way to create radio and check box groups.
Whatever is processing the submission of such data (servlet, for example) needs to be aware that multiple request parameters with the same name are being used.
hth,
bear
 
Author
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the official W3C spec on XHTML 1.0, the NAME attribute is just a CDATA, which can be any valid text.
XHTML 1.0 Transitional DTD
The ID attribute, however, is an ID field which MUST be unique across the entire document. The ID attribute is used by JavaScript to search out specific objects on the page:

Duplicate NAMEs get passed to server forms as:
form.asp?SomeName=1&SomeName=2&SomeName=3
So your server script should be prepared to handle them as an array or something.
 
reply
    Bookmark Topic Watch Topic
  • New Topic