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
Sandeep Krishnan
9,730 PointsIs the any real difference between value and Name ( in HTML inputs ?)
i am struggling with this even on open Web. I have seen previous Youtube video where the tutors have loosely and interchangeably used the name vs value attribute in an <input> Tag>>>> I understand either can be used to connect to Javascript using the post method. Alternatively you can create a class to connect to JS. SO would you think I should even use value element in an input Tag???
4 Answers
egaratkaoroprat
16,630 PointsNot quite, since you can use both on client-side (manipulation or client-sided validation) and server-side (store data in a database).
You can think of the attribute name as the variable name and the attribute value as its content.
egaratkaoroprat
16,630 PointsHi Sandeep
Value and name are different (you will see it, when you start to learn server-side programming). Value can be the text you have entered in a field, value of a checkbox or radio button that you have specified. It can even be a value from a hidden field, which you sometimes need to convey additional information.
Name on the other hand, represents the form element and gives it a name, so you can get the value out of it. For example, if you want to get a value of the field named 'firstname' and put in in a variable named $fistname via PHP, you will use something like this:
$firstname = $_POST['firstname'];
I hope this helps you.
Sandeep Krishnan
9,730 PointsThanks Egarat. Basically "Value" is for Server side and "name" is for client side usage in a sense ?
Sandeep Krishnan
9,730 Pointsah ha now I got ! that was perfect explanation variable name and content :)
egaratkaoroprat
16,630 Pointsglad I could help, happy coding! :)