Sunday, 28 August 2016

HTML Input Type Checkbox, Radio button elements

Input Type Checkbox
Checkbox is used to select or deselect one or more options from the given set of options.
Attributes of Checkbox

  • name- defines name of the checkbox
  • value- value that should be transferred to the server after selecting the corresponding option on the checkbox.
  • checked- it is used to select the checkbox by default
example

<!Doctype Html>
<html>
<body>
<h1>CheckBox</h1>
<form>
Select One or More Option: <br/>
Sports you like to watch?<br/>
<input type="checkbox" name ="option1" value="Cricket" checked="checked">Cricket<br />
<input type="checkbox" name ="option2" value="Football">Football<br />
<input type="checkbox" name ="option3" value="Hockey">Hockey<br />
</form>
</body>
</html>


Input Type Radio
Only one item can be selected at a time while in checkbox we can select multiple items at a time.
Attributes of Radio

  • name- defines name of the radio button.
  • value- value that should be transferred to the server after selecting the corresponding option on the radio button.
  • checked- it is used to select the radio button by default
example


<!Doctype Html>
<html>
<body>
<h1>Radio</h1>
<form>
Sports you like to watch?<br/>
<input type="radio" name ="group1" value="Cricket" checked="checked">Cricket<br />
<input type="radio" name ="group1" value="Football">Football<br />
<input type="radio" name ="group1" value="Hockey">Hockey<br />
</form>
</body>
</html>

0 comments:

Post a Comment