The complete guide – HTML forms for CBSE class 10 Computer Applications subject is mainly focused on the topic of HTML forms of Unit 2 – HTML.
Introduction to Forms
Dear Reader, when you are going to join any institute or company or organization or any online website subscription, you have to do registration first. In previous articles, we have discussed images in HTML, Lists in HTML, HTML formatting Tags, HTML basic elements.
Am I Right?
Yes, when you visit any one of the above, you are getting a form to submit whether online or offline. These forms simply collect your basic information like your name, date of birth, e-mail id, etc. It is mainly used for keeping records for future reference.
Apart from that, you might heard about survey forms, feedback forms, registration forms etc. All of these forms are created using HTML forms only.
HTML forms are set of different form elements that allow to interact with the user by your HTML web page and collect the data and information from user.
HTML Form fields
HTML supports certain fields to collect different information from user. These fields are as following:
- Textbox : It is used to user allow to enter a single line text field in HTML forms. Textfield is mostly used to collect Names or any single value in forms.
- TextArea: It is used to collect multi-line text entries in HTML forms. This field is used to accept the address field in a form.
- Password: It is similar to the textbox field but the characters are displayed in a special symbolic form when the user enters them. As its name, it is used to collect a password from the user.
- Radio Buttons: These fields are used to accept a single value from given multiple choices or options. It looks like a circle with a dot when selected. For example, select gender, stream like science, commerce, and humanities, etc.
- Checkbox: It is used to select multiple choices from a given set of values. It is coming in a square box with a tick mark in front of it when selected. For example hobbies, subjects etc.
- Combobox: It also provides a list but with a drop-down list. It means when users click on the small arrow coming to next to the dropdown it will expand to downwards and display the list.
- Button: Buttons are used to submit or save the data as well as clear the enterd data into form.
These fields are categorized into the following categories:
- Input : Textbox, Password, TextArea
- Select: Radio Button, Checkbox, List and Combobox
- Call to Action: Submit button or Reset Button
Inserting fields into HTML form
To insert textbox in HTML form follow this syntax:
<input type=”text” size=”n” maxlength=”n”>
<input type=”text” size=40 maxlength=”10″ value=”Enter text”>
The input tag is used to insert a textbox in HTML form. It has following attrinutes:
- type: It must text when you want to insert textbox.
- size: It specifies the width of the textbox. It must be a numeric value.
- maxlength: It is used to specify the maximum number of characters allowed on a textbox.
- value: It is used to provide the default text inside textbox.
To insert a textarea, <textarea> is used with below given syntax:
<textarea rows=”n” cols=”n”></textarea>
<textarea rows=7 cols=40 ></textarea>
The textarea tag has two primary attributes:
- rows: Specifies number of lines in the textarea field by default.
- cols: Allow number of characters allowed in a single line.
Password field allows to accept password from keyboard. the syntax is as following:
The password field can accept similar attributes as textbox.
Radio button allows to insert a circle button to select only one choice from given set of values. The syntax is as following:
<input type=”radio” name=”text” value=”text” checked>Text_2_display
<input type=”radio” name=”gen” value=”Male” checked>Male
<input type=”radio” name=”gen” value=”Female”>Female
Radio button accepts following attributes:
- name: When you want to allow to select a single value, you have give same name to all radio buttons in the form.
- value: It saves the text written as value into the database when submit button is clicked.
- checked: If you want to display the checkbox should be selected automatically when your HTML page loads in the browser, you can use this attribute.
As we have already discussed that checkbox allows to select multiple values from given choices. The syntax is almost similar like radio button. So let us take an example:
<input type=”checkbox” name=”gen” value=”Plying Cricket” checked>Plying Cricket
<input type=”checkbox” name=”gen” value=”Reading Books”>Reading Books
To create combobox you need to combine two tags in HTML form.
- Select : To create a list
- Option: To create item list to fill in combobox.
There are three types of buttons:
- Submit: It allows to save data.
- Reset: It allows to clear the form.
- Button: It is mostly used to run the developer’s code.
The syntax is as following:
<input type=”button” value=”text”>
<input type=”submit” value=”Save”>
<input type=”reset” value=”reset”>
Creating a form in HTML
A form tag is used to create a form in HTML. The syntax for form tag is as following:
<form action=”file” method=”method”>….</form>
The form tag has following attributes:
- Action: This accept the file name or page should be redirected after click on the button.
- Method: This specifies how the data will be saved either get or post after click. The value get means getting data and post means sending data through the form into server.
Rate this post and give your valuable feedback by filling up below given form.