Using the input Element to Obtain a Boolean Response

Description

The checkbox type of the input element creates a check box that allows the user to make a true/false choice.

This value for the type attribute supports the additional attributes shown in the following list.

  • checked - If applied, check the checkbox when initially displayed or when the form is reset.
  • required - Specifies that the user must check the check box.
  • value - Sets the value submitted to the server when the check box is checked.

Example

The following code shows the checkbox type of input element in use.


<!DOCTYPE HTML>
<html>
<body>
  <form method="post" action="http://example.com/form">
    <p>
      <label for="veggie"> Are you vegetarian:
      <input type="checkbox" id="veggie" name="veggie" />
      </label>
    </p><!--from www . j a v  a  2 s .  c  o m-->
    <p>
    Which of the following skills do you possess? Select all that apply.<br />
    <input checked type="checkbox" name="chkSkills" value="html" />HTML <br /> 
    <input type="checkbox" name="chkSkills" value="xhtml" />XHTML <br /> 
    <input type="checkbox" name="chkSkills" value="CSS" />CSS<br /> 
    <input checked type="checkbox" name="chkSkills" value="JavaScript" />JavaScript<br />
    <input type="checkbox" name="chkSkills" value="aspnet" />ASP.Net<br />
    <input checked type="checkbox" name="chkSkills" value="php" />PHP    
    </p>
    <input type="submit" value="Submit Vote" />
  </form>
</body>
</html>

Click to view the demo





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed