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

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 91,253 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,149 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.