Reputation: 1559
I took the maintenance of a really old java web application. (Recently it was passed from tomcat 4 to tomcat 6, and maybe this caused the problem.)
In the jsp there is a table that have inside this column (where elenco is a java array of objects and elenco[y] means a different object for each row of the table). So basically it is a radio button for every row:
<form name="index" action="elencoRichiesteFotoImpronte.jsp">
<td width="5%"><div align="center"><input type="radio" value="<%=elenco[y].getId()%>" value1="<%=state%>" value2="<%=elenco[y].getNameOp()%>" data-val2="<%=elenco[y].getNameOp()%>" name="selrec" id="selrec" ></div></td>
</form>
(I added the attributes data-val2, to make some attempts with html-5, but didn't worked. And I added too the id, because in the code that I inherit was not present). In the same jsp there're a lot of parts in javascript that access to the selected value of radiobutton, for example:
alert(document.index.selrec.value2);
But it shows that the value is undefined and so most of the code doesn't work. Does exist an easy way to access to the selected custom value of the radiobutton without making big changes to all the code (maybe some HTML tags)? (And possibly without using jquery.)
Upvotes: 0
Views: 123
Reputation: 2186
Yes this can be done.
alert(document.getElementById('selrec').getAttribute("value2"));
This accesses the custom attributes of the Radiobutton
Upvotes: 1