Woi Shingo
last year
Woicountry asked

Whats the name at textarea for?

Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hello Woi Shingo! The <textarea> tag includes the name attribute to identify the data that the text area collects when the form is submitted. This is a common aspect of form elements, which are grouped together within a form tag.

When a form is submitted, the values of the form inputs are sent to the server. The name attribute gives a unique identity to each input, helping the server distinguish between the different pieces of data.

For example, in your current HTML code:

<form action="/html-form-submit" method="post">
    <label>Write a movie plot.</label><br>
    <textarea name="plot" rows="3" cols="40"></textarea>
</form>

Here, name="plot" tells the server that whatever text the user enters into the text area should be associated with the plot identifier once the form is submitted.

Consider this scenario:

Imagine needing to capture both a movie title and its plot in a form. You might adjust your code to look like this:

<form action="/html-form-submit" method="post">
    <label>Movie Title:</label><br>
    <input type="text" name="title"><br>
    <label>Write a movie plot:</label><br>
    <textarea name="plot" rows="3" cols="40"></textarea>
</form>

Here, you'd have two inputs each with a different name:

1. name="title": captures the movie title.

2. name="plot": captures the movie plot.

When this form is submitted, the server will know exactly which text is the title and which is the plot.

Hope this helps make sense of the name attribute! Let me know if you have more questions, or if there's anything else you'd like to understand better. 😊

HTML
This question was asked as part of the Learn HTML course.