...

View Full Version : multiple fields with same name?



mrmigu
12-15-2005, 05:22 PM
hi, ive got a form with several fields with the same name, though only one is enabled at a time. This works when i submit the data, ie only the enabled field data gets submitted, but my javascript doesnt like reading/changing the values of the enabled field. it doesnt seem to like the fact that ive got more than one field with the same name

is changing the field names so that they are all unique my only option here to get javascript to like my form??

liorean
12-15-2005, 05: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.

jbot
12-16-2005, 10:36 AM
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.

liorean
12-16-2005, 09: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.

Pyth007
12-19-2005, 12: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...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum