Checkbox.checked : CheckBox « Form « JavaScript Tutorial






Syntax

document.form.checkbox.checked

The checked property holds the current state of a check box.

Because this property is a read/write Boolean, the state of the check box can be altered by changing this property.

<html>
    <form name="orderForm">
      <input type="checkbox" name="door4">4 doors<br>
      <input type="checkbox" name="door2">2 doors<hr>
      Step 2:
      <input type="button" value="Submit Order" name="orderButton" onClick="submitOrder()">
    </form>
    <script language="JavaScript">
    <!--
    function submitOrder() {
      if((document.orderForm.door4.checked == true) && (document.orderForm.door2.checked == true)){
        alert("You selected two different door styles. Reselect door style.");
        document.orderForm.door4.checked = false;
        document.orderForm.door2.checked = false;

      }else if((document.orderForm.door4.checked == false) && (document.orderForm.door2.checked == false)){
        alert("You did not select a door style! Please select a door style.");
      } else  {
        var alertString = String("Order: ");
        if(document.orderForm.door4.checked == true)
          alertString += "4 doors.";       
        if(document.orderForm.door2.checked == true)
          alertString += "2 doors.";       
        alert(alertString);
      }
    }
    -->
    </script>
    </html>








10.7.CheckBox
10.7.1.Checkbox
10.7.2.Checkbox.blur()
10.7.3.Checkbox.checked
10.7.4.Checkbox.click()
10.7.5.Checkbox.defaultChecked
10.7.6.Checkbox.focus()
10.7.7.Checkbox.form
10.7.8.Checkbox.handleEvent()
10.7.9.Checkbox.name
10.7.10.Checkbox.onBlur
10.7.11.Checkbox.onClick
10.7.12.Checkbox.onFocus
10.7.13.Checkbox.type
10.7.14.Checkbox.value
10.7.15.Check if a CheckBox checked
10.7.16.With with RADIO and CheckBox
10.7.17.Use checkbox to control the window style
10.7.18.A Checkbox and an onclick Event Handler
10.7.19.A Checkbox, an onclick Event Handler and show/hide form controls