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 trialTerrence Wells
14,609 PointsWhat's the difference between the value and name attribute?
I don't understand the difference between the two. Don't they both have something to do with what goes back to the server.
1 Answer
Kevin Korte
28,149 PointsThe value attribute is what is going to get sent back to the server. For instance you can set the value of an input field in the html code, which is helpful for hidden or disabled inputs.
The name attribute is how you reference the input, once the value from the input gets sent back to the server.
For example this html
<input type="text" name="name" value="Kevin">
when the form gets submitted (let's assume I'm using PHP)
<?php
$name = $_POST['name'];
//now $name is set to "Kevin"
var_dump($name); //would return Kevin to the screen
Terrence Wells
14,609 PointsTerrence Wells
14,609 PointsI get it! Thank you!