Is it valid to have two input elements with the same name?

Yes, it is valid

This is Good

<form name="form1">
  <input type="hidden" name="url" value="1">
</form>

<form name="form2">
  <input type="hidden" name="url" value="2">
</form>

This is also fine and will generally be interpreted as an array of values, e.g. {url: [1, 2]}, depending on what your server does. In a URL encoding, it will look like url=1&url=2.

<form name="form1">
  <input type="hidden" name="url" value="1">
  <input type="hidden" name="url" value="2">
</form>

Yes.

More, it is essential if you are dealing with radio button groups.


"This is Not Good" parses correctly on every browser I know of; if two url's appear in the url encoded string, it will be treated as an array. Try this in JQuery:

$('<form name="form1">\
     <input type="hidden" name="url" value="1">\
     <input type="hidden" name="url" value="2">\
</form>').serialize()

and you will get: "url=1&url=2"

a well-written query string parser will return a json structure like this:

 {"url":["1", "2"]}

Is it strictly spec? Nope, but neither is creating a multi-line string by escaping the EOL with a backslash, as I did above.


Yes -- each will only submit with their respective forms.

If you have them in the same form, one will override the other and it is not valid.

EDIT: As pointed out by Mahmoodvcs that the overriding only occurs in some languages (such as PHP) as is not inherent within HTML itself.


To test if it is valid or not, creat you page and test at W3C here :

http://validator.w3.org/