Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCaroline Louw
12,155 Pointswhat is the function of the value attribute in an input tag because it wasn't part of the input tag before?
when doing forms
1 Answer
Clinton Hays
Front End Web Development Techdegree Graduate 18,156 PointsHi Caroline!
The "value" attribute is the information sent to the back end after the user submits a form. It isn't used for text, email, or password because the "value" is the information entered by the user.
However, radio buttons, checkboxes, selects, etc., have predefined "values" for the user to select from. When we write the code we have to assign the information to the "value" attribute so it can be sent to the back end.
For example:
<input type="checkbox" id="development" value="interest_development" name="user_interest"><label for="development" class="light">Development</label>
This markup says that the browser should render a checkbox next to some text that reads "Development." The text inside the <label>
element is only a label displayed in the browser. We have to use the "value" attribute in the <input>
element to make sure that the information sent to the server reads "interest_development."
I hope that makes sense! Happy coding!