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 Form Basics The Textarea Element

Arikaturika Tumojenko
Arikaturika Tumojenko
8,897 Points

Understanding the values for the "name" attribute.

Are all the values used until now in the video pre estabilished or we could give the attribute name any value we want (<input type="text" id="name" name="threehouse_form"> for example)?

4 Answers

Alexander Peschel
seal-mask
.a{fill-rule:evenodd;}techdegree
Alexander Peschel
Front End Web Development Techdegree Student 11,181 Points

The first element in the document with an ID matching the value of the for attribute is the labeled control for this label element.https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input

The name attribute is for fetching values after submitting the form.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,845 Points

Hi there,

Yes generally we can give the name attribute any value we want.

There are one or 2 caveats in the way the attribute is used, For example the name attribute works with the label "for" attribute and the names must be the same but to my knowledge there's no limit to what values you could feasibly use. :p-)

Arikaturika Tumojenko
Arikaturika Tumojenko
8,897 Points

Ok, I understand. Still haven't got to labels so I think the answer will become more clear later. Thx :).

Kevin Korte
Kevin Korte
28,111 Points

I think Jonathan is right, as long as the name attribute is a string value, you should be able to make it whatever you want. You'll just want your label for attribute to match as he said.

You'll just need a matching attribute to grab the form data on the server side.