Checkbox : CheckBox : Form JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Form » CheckBox »

 

Checkbox












The Checkbox object represents a graphical check box.

Check boxes are created as part of a form by using the tag with the TYPE attribute set to checkbox in an HTML document.

Once created, check boxes can be accessed in JavaScript as an element of a form using dot notation.

Check boxes can also be grouped together under the same name and accessed as an array by using brackets.

Arguments, Properties, Methods, and Event Handlers Associated with the Checkbox Object are listed in the following table.























































checked A Boolean value that determines if the check box is checked.
defaultChecked A Boolean value that holds the initial state of the check box. This value is set with the CHECKED attribute.
form Returns the Form object of the check box.
name The string specified in the NAME attribute of the HTML tag.
type The string specified in the TYPE attribute of the HTML tag. This string is always checkbox for the Checkbox object.
value The value returned when the form is submitted.
blur() Removes focus from the check box.
click() Calls the check box's onClick event handler.
focus() Applies focus to this check box.
handleEvent() Passes an event to the appropriate event handler associated with the check box.
onBlur The handler invoked when focus is removed from the check box.
onClick The handler invoked when the check box is selected.
onFocus The handler invoked when focus is applied to the check box.















<html>
    <script language="JavaScript">
    <!--
    function submitOrder()
    {
      var alertString = String("Order: ");
      if(document.orderForm.lettuceCB.checked == true)
        alertString += " with lettuce ";      
      if(document.orderForm.cheeseCB.checked == true)
        alertString += "with cheese ";        
      if(document.orderForm.tomatoeCB.checked == true)
        alertString += "with tomatoe ";       
      alert(alertString);
    }
    -->
    </script>
    <form name="orderForm">
      Lettuce
      <input type="checkbox" value="lettuce" name="lettuceCB"><br>
      Cheese 
      <input type="checkbox" value="cheese" name="cheeseCB"><br>
      Tomatoe
      <input type="checkbox" value="tomatoe"name="tomatoeCB"><hr>
      Step 2:
      <input type="button" value="Submit Order" name="orderButton" onClick="submitOrder()">
    </form>

    </html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Form
» CheckBox