tags:

views:

60

answers:

4

So I have

<form id="formA">
 <input id="uuid">
</form>

<form id="formB">
 <input id="uuid">
</form>

is this ok to have 2 field names on different forms? I'm thinking access via javascript.

+7  A: 

The same name? Yes. They can be in the same form for that matter (this is essential for radio button groups!)

Your example, however, has two elements with the same id which is not OK. An id must be unique within a document.

David Dorward
Thank you. I guess I was thinking of accessing via a form reference, but the id should be unique on the page..
Brett
+3  A: 

It's okay to have two names that are the same, but in your example you have two ids that are the same, which is not valid.

Jimmy Cuadra
+2  A: 

No, identical ids in a document are invalid. You can have multiple names in different forms, though.

Pekka
A: 

David is correct from a "good programming" stand-point. By definition an "id" should be unique. However, if you HAD to have this, you could access those input nodes, you would just need to access their parent, first.

El Guapo
There is no almost about it. By definition an id must be unique.
David Dorward
very true!!! I actually was typing one thing, then decided to type something else and hit the "Add Answer" before I could take out the Almost...
El Guapo
Hooray for being able to edit it :)
David Dorward