Hi Vineeth,
I am going to give you an example of how to do it.
Below is the code of the form I am going to write
<table width="390">
<tr>
<th colspan="2">Radio Button demonstration</th>
</tr>
<tr>
<td>
<input type="radio" checked="checked" name="radioSel" id="radio1" onclick="ShowHideBasedonRadio('divFn')" />Show First Name
</td>
<td>
<div id="divFn" style="display:;">
<input type="text" id="txtFName" value="First Name" />
</div>
</td>
</tr>
<tr>
<td><input type="radio" name="radioSel" id="radio2" onclick="ShowHideBasedonRadio('divLn')" />Show Last Name </td>
<td>
<div id="divLn" style="display:none;">
<input type="text" id="Text1" value="Last Name" />
</div>
</td>
</tr>
</table>
<table width="390">
<tr>
<th colspan="2">Check Box demonstration</th>
</tr>
<tr>
<td>
<input type="checkbox" id="check1" onclick="ShowHideBasedonCheckbox(this, 'div1')" />Show First Name
</td>
<td>
<div id="div1" style="display:none;">
<input type="text" id="Text2" value="First Name" />
</div>
</td>
</tr>
<tr>
<td><input type="checkbox" id="check2" onclick="ShowHideBasedonCheckbox(this, 'div2')" />Show Last Name </td>
<td>
<div id="div2" style="display:none;">
<input type="text" id="Text3" value="Last Name" />
</div>
</td>
</tr>
</table>
Following is the JavaScript code that will fire after clicking on radion button and checkbox.
<script language="javascript" type="text/javascript">
function ShowHideBasedonRadio(id)
{
if (id == 'divFn')
{
document.getElementById('divFn').style.display = '';
document.getElementById('divLn').style.display = 'none';
}
else
{
document.getElementById('divFn').style.display = 'none';
document.getElementById('divLn').style.display = '';
}
}
function ShowHideBasedonCheckbox(chk, id)
{
chk.checked == true ? document.getElementById(id).style.display = '' : document.getElementById(id).style.display = 'none';
}
</script>
Please let me know if this is what your requirement is. I have attached one demo file also that is the working example of the code.
Regards
Download source fileRegards,
Sheo Narayan
http://www.dotnetfunda.com
Vineeth1311, if this helps please login to Mark As Answer. | Alert Moderator