Language References
Sets or retrieves whether the given check box or radio button is selected.
Inline |
<element CHECKED ... > |
Script |
input.checked = bChecked ] |
false |
The control is not selected. |
true |
The control is selected. |
This property returns or accepts only a boolean value, meaning true if set, and false if not. The property is read/write with a default value of false.
Check boxes that are not selected do not return their values when the form is submitted.
The following example demonstrates how to retrieve the checked property and triggers an action if the property is set.
<script language="JavaScript">
<!--
function chkThis ( ) {
var msg = "This property can be used to detect if a checkbox option has been selected. " +
"A script could be written to track the checkbox status and do further processing " +
"once the checkbox has been checked.";
if ( document.forms [ 0 ].elements [ 'chkBox' ].checked ) {
el = document.all ? document.all [ 'msg' ] : document.getElementById ( 'msg' );
if ( document.all ) el.innerHTML = msg;
else if ( dom ) el.childNodes [ 0 ].nodeValue = msg;
else if ( document.layers ) alert ( msg );
}
else {
if ( document.all ) el.innerHTML = "";
else if ( dom ) el.childNodes [ 0 ].nodeValue = "";
}
}
//-->
</script>
...
<body>
<form>
<p>Check here if you wish to learn more about checkboxes
<input name="chkBox" type="checkbox" onclick="chkThis ( )">
</p>
</form>
<div id="msg"></div>
</body>
Show me
INPUT type=checkbox, INPUT type=radio
defaultChecked