This tutorial is designed to help you add <select>
and <textarea>
elements to your HTML forms. These elements provide more diverse opportunities for users to input data into your website.
By the end of this tutorial, you'll:
<select>
and <textarea>
HTML tags.<select>
tag.<textarea>
tag.Prerequisites: Basic understanding of HTML and HTML forms.
<select>
The <select>
tag is used to create a drop-down list. The <option>
tags nested inside the <select>
tag define the available options in the list.
Example:
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<textarea>
The <textarea>
tag is used to define a multi-line input control (a text area).
Example:
<textarea name="message" rows="10" cols="30">
The cat was playing in the garden.
</textarea>
<select>
Here's an example of a <select>
element with different options:
<select name="carBrand">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
This code will create a drop-down list with car brands. The value
attribute in the <option>
tag is what gets sent as the form data.
<textarea>
Here's an example of a <textarea>
element:
<textarea name="message" rows="5" cols="50">
Write your message here.
</textarea>
This code creates a text area for users to input a message. The rows
and cols
attributes define the visible width and height of the text area.
<select>
and <option>
tags.<textarea>
tag.For further learning, you can explore how to handle the data from these form elements using server-side languages like PHP or Node.js.
<select>
element that lets users choose their favorite fruit.Solution:
<select name="favoriteFruit">
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="cherry">Cherry</option>
</select>
<textarea>
element that lets users write a short bio.Solution:
<textarea name="bio" rows="5" cols="50">
Write your short bio here.
</textarea>
<select>
and a <textarea>
element. The <select>
should let users pick a topic, and the <textarea>
should let them write a message about that topic.Solution:
<select name="topic">
<option value="sports">Sports</option>
<option value="music">Music</option>
<option value="movies">Movies</option>
</select>
<textarea name="message" rows="5" cols="50">
Write your message about the selected topic here.
</textarea>
For further practice, try to handle the form data using a server-side programming language of your choice.