I am working on Struts 1.1 framework. In JSP Page, I am using a <html:select property="something"> tag.

My doubt: In javascript we generally apply some properties to an element by using its id attribute as an identifier.
for eg.
html = <p id="x"></p>
javascript = document.getElementById['x'].style.display = "block";

I was doing reverse engineering of this code and since my application is very vast, due to some reasons I am not able to clearly find out if its true whether we can use the property attribute of the struts tags in place of id while identifying it.
for eg.
struts tag = <html:select property="abc"></html:select>
javascript = document.getElementById['abc'].style.display = "block";

(Note that I know we can use the styleId attribute in struts tags to define an id. I am only trying to find out if its possible this way)

1

There are 1 answers

0
Mar On

Take a look at the html rendered from one of these pages, and you'll find that for inputs the property in a struts tag becomes name in the rendered html tag.

If you want to add the id attribute to an html tag rendered from a struts tag, try adding the styleId attribute in the struts tag. For example:

<html:select property="abc" styleId="abc123"> ... </html:select>

renders out to:

<select name="abc" id="abc123"> ... </select>

Note that styleId can be the same as property. You can also get elements by name instead of id in javascript, but since id is supposed to be unique and name isn't, you'll have to deal with an array of elements.