Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!