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.

JavaScript Treehouse Club - MASH MASH - HTML Forms/Divs/Input

Reuven Kishon
Reuven Kishon
5,270 Points

Form questions

Hello there,

I have a few questions around the form tag that I hope you can help me with:

1) What is the purpose of the ID attribute? 2) Are there any attributes that get assigned a default value if you do not explicitly give them a value?

3 Answers

Josh Olson
Josh Olson
13,236 Points

What is the purpose of the ID attribute?

An ID attribute helps your CSS and Javascript find that particular tag. I know it looks ugly and redundant with the name attribute set as the same thing, i.e.

<input type="text" id="flavor" name="flavor">

But the name attribute along with its value is what gets sent whenever the user submits your form, not the ID attribute. Additionally a server will expect the name to have semantic meaning - it has to be named such and such. This is why your ID and name might not match.

You can do without an ID attribute if you don't have any CSS or Javascript that needs to directly find that tag.
You can do without a name attribute if you don't have any server-sided code reliant on that input.

Are there any attributes that get assigned a default value if you do not explicitly give them a value?

Currently there is no way to send a default value to a server. You can double check here.

Okay so what happens when you try to send a default value? From what I've seen writing backend servers with Node, your HTML might look like this.

<input type="text" name="user">
<input type="text" name="pass">
<input type="text" name="email">

And if the user filled out everything, you'll get JSON data back that looks like this:


However If nothing was typed into the email field, you get this:


Both the value and the name won't get sent. It's left to the server to decide what to do here. You can also do this client sided with Javascript and change the value before the form is submitted. Unfortunately there is no pure HTML solution.

Does that answer your questions?


The purpose of the ID attribute is to be a unique identifier for a element. A class can be used on multiple elements, but an ID can only be used on one element.

Some examples of default attribute values:

textarea cols attribute - default is '20'

button type attribute- default is 'submit'

form target attribute - default is '_self'

Check out the MDN HTML Element reference - Pick a form element > Ctrl + F > 'default'.

Hope this helps :)

id is are more specific than a class selector