tags:

views:

181

answers:

3

Do input field NAMES have to be unique across forms?

I would imagine that it's ok since the reference to each input field is qualified by the form name.

document.form1.inp1.value document.form2.inp1.value

Am I right? Will it work in all browsers?

thanks

A: 

No they do not have to be unique across forms, but should be unique within forms except for radio buttons.

Nosrama
thanks. I tried to click on the up arrow vote and it's giving me a -1?
sdfor
+3  A: 

No, they don't have to be unique across forms or within forms. The most common use of repeating them is radios:

<form>
    <input type="radio" name="my_radio" value="1">
    <input type="radio" name="my_radio" value="2">
    <input type="radio" name="my_radio" value="3">
</form>
Greg
+1  A: 

Radio buttons need the same name to group properly. Depending on what sort of back-end is handling your form after it's submitted, some people name radio buttons and checkboxes with a "[]" after their name to make them convert nicely to arrays in the form handling system.

If several forms are pointing back to the same form handler (i.e. many define the form as <form action="form_handler.php">), you can have similar names for field elements, but the form handler would need a unique entry on each page to differentiate them. It would be best practice to have unique names for each input field, even across multiple pages, if they're all part of one information-gathering session.

MidnightLightning