/    Sign up×
Community /Pin to ProfileBookmark

Clear Radio Boxs

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>
[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@wallacedmFeb 23.2004 — You're missing a double quote after

id="q1_tr

and

id="q2_tr

Correct this and try again. I haven't had a good look; there might be more problems.
×

Success!

Help @rpanning spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...