Chapter 7 HTML Frames and Forms
Chapter 7 HTML Frames and Forms
Form Attributes
Apart from common attributes, following is a list of the most frequently used
form attributes
HTML Form Controls
There are different types of form controls that you can use to collect data
using HTML form:
a. Single-line text input controls: is used for items that require only one line
of user input, such as search boxes or names. They are created using
HTML <input> tag. Here is a basic example of a single-line text input
used to take first name and last name
<!DOCTYPE html>
<html>
<head> <title>Text Input Control</title> </head>
<body>
<form >
First name: <input type = "text" name = "first_name" /> <br>
Last name: <input type = "text" name = "last_name" /
</form>
</body>
</html>
Attributes: -Following is the list of attributes for <input> tag for creating text
field.
b. Password input controls
This is also a single-line text input but it masks the character as soon as a
user enters it. They are also created using HTML <input> tag. Here is a basic
example of a single-line password input used to take user password:
<!DOCTYPE html>
<html>
<head> <title>Password Input Control</title> </head>
<body>
<form >
User ID : <input type = "text" name = "user_id" /> <br>
Password: <input type = "password" name = "password" />
</form>
</body>
</html>
Attributes: -Following is the list of attributes for <input> tag for creating
password field.
c. Multi-line text input controls
This is used when the user is required to give details that may be longer than
a single sentence. They are created using HTML <textarea> tag. Here is a
basic example of a multi-line text input used to take item description:
<!DOCTYPE html>
<html>
<head> <title>Multiple-Line Input Control</title> </head>
<body>
<form>
Description : <br />
<textarea rows = "5" cols = "50" name = "description">
Enter description here...
</textarea>
</form>
</body>
</html>
6. Button Controls
There are various ways in HTML to create clickable buttons. You can also
create a clickable button using <input>tag by setting its type attribute to
button. The type attribute can take the following values
Here is example HTML code for a form with three types of buttons
<!DOCTYPE html>
<html>
<head> <title>File Upload Box</title> </head>
<body>
<form>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
<input type = "button" name = "ok" value = "OK" />
<input type = "image" name = "imagebutton" src =
"/html/images/logo.png" />
</form>
</body>
</html>
7. Hidden Form Controls
Hidden form controls are used to hide data inside the page which later on
can be pushed to the server. This control hides inside the code and does not
appear on the actual page. For example, following hidden form is being used
to keep current page number. When a user will click next page then the
value of hidden control will be sent to the web server and there it will decide
which page will be displayed next based on the passed current page. Here is
example HTML code to show the usage of hidden control
<!DOCTYPE html>
<html>
<head> <title>File Upload Box</title> </head>
<body>
<form>
<p>This is page 10</p>
<input type = "hidden" name = "pagename" value = "10" />
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset” value = "Reset" />
</form>
</body>
</html>