Form Elements
Form Elements
What is form?
- bring together parts or combine to create (something).
- A form is a document with spaces in which to write or select, for a series of documents with similar
contents. The documents usually have the printed parts in common, except, possibly, for a serial
number.
- a printed or typed document with blank spaces for insertion of required or requested
information.. (Wikipedia)
1. Text Attribute
- Text is the default, with size used to specify the default size of the box that is created or how many
characters wide the text area will be. The default size is 20 characters.
Syntax:
<input text name=”label” size=”value of the size of the box”>
Sample:
<Body>
<Form>
Name: <Input type=”text” Text Name: “full name” size=”30”>
Age: <Input type=”number” Text Name: “age” size=”2” maxlength=”2”>
OUTPUT: in the text box name you can type up to 30 characters, in the textbox of age you can only type 2
number.
2. Using text area tag
- The <textarea> tag allows you to produce a box that can contain several lines of text.
- The TEXTAREA tag requires a unique name, specified with NAME=.
- You can specify the size of your text by using the ROWs and COLS attributes.
- It needs a closing tag for TEXT area.
Attribute Function
Rows determines the number of lines in the box
Cols Specifies the width of the lines
Sample:
<Body> <Form>
Name: <Input type=”text” Text Name: “full name” size=”30”>
Age: <Input type=”number” Text Name: “age” size=”2” maxlength=”2”>
<br> Describe yourself: <br>
<textarea name=”feedback” rows=”5” Cols=”60”> </textarea>
*textarea is a good way to allow the users to give their own views.
But as soon as the site becomes very busy, they might not have the
time to read all their messages. It would be better if you limit the
choices from a predefined list so that you can manage your site more
effectively.
<html>
What ice cream flavors would you like?
<select name=”Flavor”>
<option> Vanilla
<option> chocolate
<option selected> Peach
</select>
</html>
OUTPUT : this is a sample output of select tag and option tag. Select tag is used to select the
default option that will appear in the drop-down menu. Option tag is used to put words that will
serve as options in the drop-down list.
5. Password Tag
- This tag requires the user to enter password
- Maxlength attribute specifies the maximum number of characters a user may enter into the field.
Syntax:
<input type= “password” name=”password” size=”10” maxlength=”10”>
Sample:
<html>
<label for="pwd">Password:</label>
<input type="password" id="pwd" name="pwd">
</html>
Syntax:
<input type=”checkbox” name=”name” value=”value>
Sample:
<html>
<p>What is your Favorite food?
<br>
<input type="checkbox" name="food" value="salad"> salad
<br>
<input type="checkbox" name="food" value="meat"> sinigang
<br>
<input type="checkbox" name="food" value="fish"> anything but fish
</html>
OUTPUT:
Sample:
<html>
What is your gender?
<br>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<input type="radio" id="other" name="gender" value="other">
<label for="others">Other</label>
</html>
8. Inserting an image
- Instead of just merely using the text submit as your button you can be more creative by using
an image.
Syntax: <Input type=”image” src=”filename”>