Disable radio button on page load

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lina531
Forum Newbie
Posts: 6
Joined: Sat Nov 26, 2011 12:04 am

Disable radio button on page load

Post 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......
Gopesh
Forum Contributor
Posts: 143
Joined: Fri Dec 24, 2010 12:48 am
Location: India

Re: Disable radio button on page load

Post 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
lina531
Forum Newbie
Posts: 6
Joined: Sat Nov 26, 2011 12:04 am

Re: Disable radio button on page load

Post by lina531 »

this code really worked ...................

thanx.............
Post Reply