form
In this module we will do the following:
Discuss the need for the form, label, and input tags.
Create a basic form.
Discuss fieldset and consolidating all items in a form together.
Discuss legend tag for creating nice looking heading in border.
Recreate form with radio buttons and checkboxes.
File Location
For this module, you should be working in the following location:
Description
It goes without saying, forms are everywhere on the web. From signing in to an application to ordering something on Amazon, we've all used forms. At some point as a new developer, you will work with forms.
Sample Code
Add the following sample code to your file:
Discussion
We're starting to build on the foundation we've established, and you can probably see many of the subjects we've discussed starting to come together. In this file, we use h1
, h2
, p
, div
and, from the last lesson, input
. We've started to describe our elements with a little more detail as well, using attributes
on the input fields specifying the type
that we want rendered. The result is that we're able to clearly state that we want a text box here, a checkbox there, and radio boxes in all the other places.
With a solid grasp on these concepts, we're able to package elements inside of a <form>
to describe a coherent collection of elements. <fieldset>
empowers us to group related elements even more tightly inside a form, and also gives us access to the <legend>
tag, which is what defines a caption for the <fieldset>
element.
Finally, the <textarea>
tag provides a multi-line text input field. It's possible to specify the number of rows and columns within a given <textarea>
. However, as you can see from our example, it's not necessary.
Challenge
Try experimenting with the different elements we've just learned about and incorporating previous lessons into your efforts. Test adding attributes
like rows
to your <textarea>
and see how that changes what's displayed.
Extra Reading
Last updated