views:

35

answers:

2

I some divs with forms inside of them and i do have inputs with same ids but in different divs and forms so do like this:

$("divEdit form #ParentId").val(12);

it works on chrome/mozilla but not on IE8
anybody knows why ?

+4  A: 

You can't have multiple elements with the same id on the same web page. You'll need to use some other method of identification such as a class (or with form controls the same name).

RoToRa
do I need to also set id,name for all my forms (is there such a rule) ?
Omu
No. You only need to use an ID if you need to identify/find that element for example in a JavaScript/jQuery or a Stylesheet. You need to set the name of a form control if you want its value to be submitted (which however is most of the time).
RoToRa
+2  A: 

ID attributes must be unique in web pages. It's part of the specification and you will always run into issues using the same id more than once.

http://www.w3.org/TR/html401/struct/global.html#h-7.5.2

Andy E