Thursday, April 16, 2009

Checkbox read only

The below code will explain how can we make the checkbox enable and disable. Here we use the function deDemo() to enable / disable the checkbox and return the value of the checkbox is enabled.

<html>
<head>
<script type="text/javascript">
function doDemo(form) {
var cbObj = form.cbObj;

if (cbObj.checked)
alert("Value is " + cbObj.value);
else
alert("No value will be submitted.");

if (cbObj.disabled)
cbObj.disabled = false;
else
cbObj.disabled = true;
}
</script>
</head>
<body>
<center>
<b>Read-only Checkbox Demo</b>
<form>
<input type="checkbox" name="cbObj" value="Y" disabled>
<p>
<input type="button" value="Execute" onClick="doDemo(this.form)">
</form>
<hr>
</center>
</body>
</html>

No comments:

Post a Comment