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 trial
Paul Barron
6,595 Pointsvalue="" vs. name=""
I'm learning about forms. What's the difference between value and name?
3 Answers
Kenneth Love
Treehouse Guest TeacherAssuming HTML, value is the value of the input/textarea/option. So:
<option value="3">three>/option>
The option has a value of 3, so that's what whatever script is processing my form will receive. We have to zoom out just a bit for name, though.
<label>Favorite number
<select name="number">
<option value="3">three</option>
</select>
</label>
The select has a name of "number", so the processing script will get something like number=3 for the name and value of the field. Some fields have both attributes on them, like:
<input name="username" value="kennethlove">
So the field will be pre-filled when the form is rendered (i.e. it will have "kennethlove" in it already as real text) and if the form is submitted just like that, the backend will get username=kennethlove.
Hope that helps!
Paul Barron
6,595 PointsI'm still kind of confused, but I assume I will learn more about this when I get to the action="" part no? Just to clarify, the value is what is reported to the action or form rendering right? Eureka!!! ...I think. Thanks for the help. I love this site!
Zachary Harriott
5,630 PointsVery helpful. Thank you!
Kenneth Love
Treehouse Guest TeacherPaul Barron you're jumping around a bit when you ask about action. action belongs to the form, not to any specific field in the form, and it specifies where the backend that will process the form lives. method, which also lives on the form, determines how the form will be submitted, usually via GET or POST.
Paul Barron
6,595 PointsKenneth Love I get it. I just don't understand what value is for, but I do understand that whatever you put as the value will appear. That said, if the form is being filled by someone else why have a value at all?
Kenneth Love
Treehouse Guest Teachervalue is useful in two main situations.
a) You're showing a form with existing data, like someone editing their profile. You want the field to contain the appropriate values, so you fill in the value attribute with their existing data.
b) You're using a select field, so each option needs a value set, or you're using <input type="checkbox"> or <input type="radio">, both of which need to have value set so they actually transmit a value to the backend.
Scott Magdalein
1,667 PointsScott Magdalein
1,667 PointsCan you provide more context for your question? What language are you referring to? What are you trying to accomplish? Is this related to forms or programming variables?