This problem came to me today. I work in a web project (Struts 2) with a lot of JSPs, and most elements input, select, table and a defined only with the attribute name , no id , for example:
<input name="myname" class="myclass" value="" type="text"/>
So far, so good, except that, unfortunately, there is a lot of javascript validation for these fields, and as far as I could read the code before leaving most, actually refer to elements with document.getElementById .
The trap here is that this is an old application (not so much old actually), compatible only with IE-6 and IE-7 (I did not search the network to understand how IE actually seems to find an element with only with the name attribute, but I think it should do something). No wonder every other browser complains and cries.
So, I'm trying to find a simple solution: find all the JSPs that define the input, select, table and a elements with the name attribute but not id to fix the HTML.
Using my good friend http://rubular.com I came up with the following:
/<(?:(input|select|a|table))\s+((?!id).)*>
This will capture every mentioned element without id . But how can I say that only those with a name matched?
Oh, another important point. The definition of the elements is on the same line, so it is most likely that there are no such things as:
<input name="..." class="..."/>