Open In App

How to Specify the Value of a Checkbox using Attribute ?

Last Updated : 20 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

To specify the value of a checkbox using an attribute in HTML, you utilize the “value” attribute within the <input> tag. This attribute allows you to assign a specific value to the checkbox, which is sent to the server if the checkbox is checked when the form is submitted.

Syntax

<input type="checkbox" name="checkbox_name" value="checkbox_value">

The table below illustrates the attributes alongside their descriptions.

Attribute Description
type="checkbox" Specifies that the input element is a checkbox.
name="checkbox_name" Identifies the checkbox when the form is submitted.
value="checkbox_value" Assign a specific value to the checkbox. This value is sent to the server if the checkbox is checked.

Features

  • Assigning Values: The “value” attribute assigns a specific value to the checkbox, which is submitted to the server if the checkbox is checked.
  • Form Submission: When the form containing the checkbox is submitted, the checkbox value is included in the form data sent to the server.
  • Identifying Checkboxes: The “name” attribute identifies the checkbox within the form, allowing you to distinguish it from other form elements.
  • Multiple Checkboxes: You can have multiple checkboxes with the same name but different values, allowing users to select multiple options.
  • Conditional Processing: Server-side scripts can process form submissions based on the values of checkboxes, enabling conditional logic and actions.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads