Disable radio button

We can enable or disable radio buttons ( Period buttons ) by using a checkbox inside a form. We know by radio button we can select on of the several available options. Let us try first by directly disabling a radio button.

Male FeMale Here is the code
<input type=radio name=sex value=male id='r1' disabled>Male 
<input type=radio name=sex value=female id='r2'>FeMale
But here we are not able to change the status as per requirement so we will use JavaScript here to manage the radio buttons by using a checkbox. Let us see how this script works. Here is the code.
<html>
<head>
<title>Demo of enable disable period button by checkbox</title>
<link rel="stylesheet" href="../images/all11.css" type="text/css">
<script language="JavaScript">
<!--

function enable_radio(status)
{
status=!status;
document.getElementById("r1").disabled=status;
document.getElementById("r2").disabled=status;
}
//-->
</script>
</head>
<body onload=enable_radio(false);>

<form name=f1 method=post action=period-disable-demock.php>
<input type="checkbox" name=others onclick="enable_radio(this.checked)" value='yes'>Others<br>
<input type=radio name=sex value=male id='r1'>Male 
<input type=radio name=sex value=female id='r2'>FeMale 
<input type=submit value=Submit>
</form>
</body>
</html>
Visitors Rating
Your Rating




Google+
More on Period button & JavaScript

Post Comment This is for short comments only. Use the forum for more discussions.




HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2018 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer