View Full Version : multiple fields with same name?
12-15-2005, 06:22 PM
12-15-2005, 06:33 PM
The only form controls that may share control name with other controls are radio buttons and checkboxes. Don't expect browsers to support multiple controls with the same name if they are not of those types.
doesn't creating field names with the same name create an array of those fields, even for non-radio fields? In PHP, you can iterate over this array, and extract their respective values.
12-16-2005, 10:15 PM
doesn't creating field names with the same name create an array of those fields, even for non-radio fields? In PHP, you can iterate over this array, and extract their respective values.In some implementations, yes. But they do that not because they have to do it to follow the specification, they do it as a way to gracefully handle code that doesn't follow the specification. In other words, you can't count on it since they could as well just always use the first element, or always the last element, or only the last to be changed. They could even set all the fields to the value entered in just one of them. And they would still follow the spec.
12-19-2005, 01:19 PM
As liorean stated, it may not be to spec., but you could use unique id's while keeping the names the same... Or use getElementsByName() and use the collection to get the specific element that you want. But if you're trying for lasting code, then its better to get as close to spec. as possible; then you won't have to continually maintain the code to make sure it works with newer browsers.
Oh, and another FYI about the name attribute: in XHTML (which some have claimed will be the spec.s for the next version of HTML), the name attribute has become depricated for some non-form elements in place of the id attribute. Although this doesn't affect your code with naming the text boxes, it would affect <div>s and <img>s that you may use elsewhere in your code...
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.