Page 1 of 1

Disable radio button on page load

Posted: Mon Feb 06, 2012 5:08 am
by lina531
<script type="text/javascript">
function disablefield(){
if (document.getElementById('yes_radio').checked == 1){
document.getElementById('forenoon').disabled='disabled';
document.getElementById('forenoon');
document.getElementById('afternoon').disabled='disabled';
document.getElementById('afternoon');
}else{
document.getElementById('forenoon').disabled='';
document.getElementById('forenoon');
document.getElementById('afternoon').disabled='';
document.getElementById('afternoon');
}
}
</script>
<table>
<tr>
<td align="right" valign="top">&nbsp;</td>
<td colspan="2">
<input type="radio" name="from" id="no_radio" onChange="disablefield();" value="0.5" />
<strong>Half Day
<input type="radio" name="from" id="yes_radio" onChange="disablefield();" value="1" checked="checked" />
Full Day</strong></td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right" valign="top">&nbsp;</td>
<td colspan="2">
<input type="radio" name="half_day1" id="forenoon" value="Forenoon" />
<strong>Forenoon
<input type="radio" name="half_day1" id="afternoon" value="Afternoon" />
Afternoon</strong></td>
<td>&nbsp;</td>
</tr>
</table>

If want that on page load by default fullday is selected and forenoon and afternoon will be disabled. but if halfday will be selected then forenoon and afternoon will be enabled.

plz help......

Re: Disable radio button on page load

Posted: Mon Feb 06, 2012 5:55 am
by Gopesh
Hi,Check this FIddlehttp://jsfiddle.net/mmuU6/.it uses jquery .
It is not the right place for posting javascript queries,pls post in javascript section.
Hope it helps

Re: Disable radio button on page load

Posted: Mon Feb 06, 2012 6:35 am
by lina531
this code really worked ...................

thanx.............