There are 25 rows in a table. Each row has an attribute, an image(tick symbol) and 5 radio buttons rating the said attribute from 1-5. when one of the buttons is clicked, I want the image(tick symbol) which is previously hidden by css to be made visible.
The html is
<table>
<tr>
<td width="15px"><img id="1ai" src="../PNG Files/Untitled-3.gif" /></td>
<td style="text-align: left" >Course Structure and it's revelence</td>
<td width="6%"><input type="radio" name="1a" value="5" id="1a1" /></td>
<td width="6%"><input type="radio" name="1a" value="4" id="1a2" /></td>
<td width="6%"><input type="radio" name="1a" value="3" id="1a3" /></td>
<td width="6%"><input type="radio" name="1a" value="2" id="1a4" /></td>
<td width="6%"><input type="radio" name="1a" value="1" id="1a5" /></td>
</tr>
<tr bgcolor="#FCFFE8">
<td width="15px"><img id="2ai" src="../PNG Files/Untitled-3.gif" /></td>
<td style="text-align: left" >Syllabus and it's coverage</td>
<td width="6%"><input type="radio" name="2a" value="5" id="2a1" /></td>
<td width="6%"><input type="radio" name="2a" value="4" id="2a2" /></td>
<td width="6%"><input type="radio" name="2a" value="3" id="2a3" /></td>
<td width="6%"><input type="radio" name="2a" value="2" id="2a4" /></td>
<td width="6%"><input type="radio" name="2a" value="1" id="2a5" /></td>
</tr>
</table>
The images have been hidden through CSS. Javascript should identify which radio button is checked and then make visible the corresponding image.
You can do that like this:
When a radio is clicked, it will find the parent row of the one that is clicked, find the image in that row and show it. This assumes that the image is previously hidden with
display: none.For better long term maintenance, you should:
Once, you had done these two steps, the code might look like this:
If you had to do it in plain javascript without a full selector engine, then I’d do it differently by manufacturing the id value of the image. Assuming you had put the “choices” id on the table, it would go something like this:
And here’s a working example: http://jsfiddle.net/jfriend00/uMUem/