asp.net.ph

Skip Navigation Links

CHECKED Attribute | checked Property

Language References


Sets or retrieves whether the given check box or radio button is selected.

Syntax


Inline <element CHECKED ... >
Script input.checked = bChecked ]

Possible Values


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.

Remarks

Check boxes that are not selected do not return their values when the form is submitted.

Example

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 

Applies To

INPUT type=checkbox, INPUT type=radio

See Also

defaultChecked



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note