I’ve got this function which is supposed to show or hide an HTML object by id. Also if it is to hide the object it should also clear a list of radio buttons. It’s easier if I just post the code and an example. In example below I’ve determind that the frm_id var is not set correctly because I cannot get an alert to come up after checking for the radio type. Any help on this would be great. Thanks
[code]
<html><head><title>Test</title>
<script type=”text/javascript”>
<!–
function tglDisplay(id, tgl)
{
var tr_id = document.getElementById(id + ‘_tr’);
var frm_id = document.forms[0].id;
if (tgl == ‘show’) {
tr_id.style.display=”;
} else if (tgl == ‘hide’) {
tr_id.style.display=’none’;
// reset input by id
if (frm_id.type == ‘radio’) {
for (var i=0; i<frm_id.length; i++) {
frm_id[i].checked = false;
}
}
}
}
// –>
</script>
</head><body>
<form action=”#” method=”post” name=”test”>
<table>
<tr style=”display:none;” id=”q1_tr>
<td>Ex Question</td>
<td>
<input type=”radio” name=”q1″ value=”Yes” id=”q1_yes” onClick=”tglDisplay(‘q2’, ‘show’);”>
<label for=”q1_yes”>Yes</label>
<br>
<input type=”radio” name=”q1″ value=”Yes” id=”q1_no” onClick=”tglDisplay(‘q2’, ‘hide’);”>
<label for=”q1_no”>No</label>
</td>
</tr>
<tr style=”display:none;” id=”q2_tr>
<td>If yes, …</td>
<td>
<input type=”radio” name=”q2″ value=”Yes” id=”q2_yes”>
<label for=”q2_yes”>Yes</label>
<br>
<input type=”radio” name=”q2″ value=”Yes” id=”q2_no”>
<label for=”q2_no”>No</label>
</td>
</tr>
</table>
</form>
</body></html>