HTML HTML Forms Choosing Options Create Checkboxes

Allie O.
Allie O.
11,601 Points

Value attribute in check boxes and radio buttons

I think I missed the description of the value attribute. Why are they needed for check boxes and radio buttons? And are they required?

Thanks!

1 Answer

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Hi Allie O.

Values are REALLY important for checkboxes and radio buttons. Web forms are all about collecting information from users and sending that information to be processed by a web server (for example, storing the user's response in a database). The value property represents the information that will be sent to the server. Without it, the checkbox or radio button won't have any information to send, and the server won't have any data to store in the database for those fields.

With text fields, the value is supplied by the user typing into the field -- but users can't type a value into a radio button or checkbox, they can only pick one. So, for example, look at this HTML:

<input type="radio" name="vehicle" value="bike">I ride a bike to work
<input type="radio" name="vehicle" value="car">I drive a car to work

If the user checked the first button, "bike" would be submitted to the server as the value for "vehicle." A web server could then store that response in a database.

Allie O.
Allie O.
11,601 Points

Ah, it makes much more sense now. Thanks a lot for clearing it up!