Skip to main content
Known Participant
November 5, 2006
Answered

Javascript help/invisible/div/radio button/subradiobutton

  • November 5, 2006
  • 2 replies
  • 591 views
Javascript help/invisible/div/radio button/subradiobutton

Does anyone know how to create 2 radio button and where the second radio button have a sub radio button when it is clicked or selected.

The default will be the first main radio button

Then when the second radio button is clicked then the 2 pops up for sub selection

Thanks
In advance
This topic has been closed for replies.
Correct answer
yes u cud put the javascript code on the same page.

ive include the sample html file for your rerference



regards,
akel

2 replies

November 6, 2006
hello you cud try the following :

<form id="form1" name="form1" method="post" action="">
<table width="283" border="0" cellspacing="1" cellpadding="0">
<tr>
<td width="281"><p>
<label>
<input type="radio" name="RadioGroup1" value="radio" onclick="selectGrp()">
Radio</label>
<br />
<label>
<input type="radio" name="RadioGroup1" value="radio" onclick="selectGrp()">
Radio</label>
<br />
</p></td>
</tr>
<tr id="subgroup" style="display:none">
<td><table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td width="10%"> </td>
<td width="90%">Sub group </td>
</tr>
<tr>
<td> </td>
<td><input name="rdo" type="radio" value="radiobutton" />
Sub group element 1 </td>
</tr>
<tr>
<td> </td>
<td><input name="rdo" type="radio" value="radiobutton" />
Sub group element 2 </td>
</tr>
</table> </td>
</tr>
</table>
</form>

and the javascript code :
<script language="javascript">
function selectGrp() {
if (document.form1.RadioGroup1[1].checked)
document.getElementById('subgroup').style.display = "block"
else
document.getElementById('subgroup').style.display = "none"
}
</script>





well hope it will work

:)
akel
Known Participant
November 8, 2006
thanks
where do i put the javascript code below:
do i put it in the same page?


and the javascript code :
<script language="javascript">
function selectGrp() {
if (document.form1.RadioGroup1[1].checked)
document.getElementById('subgroup').style.display = "block"
else
document.getElementById('subgroup').style.display = "none"
}
</script>

Correct answer
November 9, 2006
yes u cud put the javascript code on the same page.

ive include the sample html file for your rerference



regards,
akel
Inspiring
November 5, 2006
You need to put the second radio button in a div which has style=visibility:hidden and then use javascript to change the visibility to visible with javascript.

Infact, I take it a step further. To start I define the visibility as visible, use javascript which initiates when the page loads and changes the visibility to hidden .... and then the other javascript function works with the radio button. This way a user with javascript disabled still gets to see everything and a user with javascript enabled gets to see the second radio button when the first one is clicked.

Check the link below: Use username as test, password also as test. Still working on this site. The radio button action is part of the "Recurrence" feature.

http://www.oncopetroleum.ca/admin/addevent.cfm