#FormsinHTML #htmlform #webtechnologylectures
HTML Forms are required, when you want to collect some data from the site visitor. For example, during user registration you would like to collect information such as name, email address, credit card
Forms are created using form element.
Attributes of form element:-
1.method:-It specifies how the data is transmitted. Possible method values are get and post.
2.action:-It specifies URL of the web page which process the form details.
HTML Form Controls
There are different types of form controls that you can use to collect data using HTML form .
1.Text Input Controls
2.Checkboxes Controls
3.Radio Box Controls
4.Select Box Controls
5.Buttons
Text Input Controls
There are three types of text input used on forms −
• Single-line text input controls − This control 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.
• 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.
• Multi-line text input controls − This is used when the user is required to give details that may be longer than a single sentence. Multi-line input controls are created using HTML textarea tag.
Single-line text input controls:-
This control 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.
Attributes
Following is the list of attributes for input tag for creating text field.
Sr.No Attribute & Description
1 type
Indicates the type of input control and for text input control it will be set to text.
2 name
Used to give a name to the control which is sent to the server to be recognized and get the value.
3 value
This can be used to provide an initial value inside the control.
4 size
Allows to specify the width of the text-input control in terms of characters.
5 Maxlength
Allows to specify the maximum number of characters a user can enter into the text box.
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 inputtag but type attribute is set to password.
Attributes
Following is the list of attributes for input tag for creating password field.
Sr.No Attribute & Description
1 type
Indicates the type of input control and for password input control it will be set to password.
2 name
Used to give a name to the control which is sent to the server to be recognized and get the value.
3 value
This can be used to provide an initial value inside the control.
4 size
Allows to specify the width of the text-input control in terms of characters.
5 maxlength
Allows to specify the maximum number of characters a user can enter into the text box.
Multiple-Line Text Input Controls:-
This is used when the user is required to give details that may be longer than a single sentence. Multi-line input controls are created using HTML textarea tag.
Attributes
Following is the list of attributes for textarea tag.
Sr.No Attribute & Description
1 name
Used to give a name to the control which is sent to the server to be recognized and get the value.
2 rows
Indicates the number of rows of text area box.
3 cols
Indicates the number of columns of text area box
Checkbox Control
Checkboxes are used when more than one option is required to be selected. They are also created using HTML input tag but type attribute is set to checkbox.
Attributes
Following is the list of attributes for input tag.
Radio Button Control
Radio buttons are used when out of many options, just one option is required to be selected. They are also created using HTML input tag but type attribute is set to radio.
ttributes
Following is the list of attributes for radio button.
Select Box Control
A select box, also called drop down box which provides option to list down various options in the form of drop down list, from where a user can select one or more options.
Attributes
Following is the list of important attributes of select tag −
Sr.No Attribute & Description
1 name
Used to give a name to the control which is sent to the server to be recognized and get the value.
2 size
This can be used to present a scrolling list box.
3 multiple
If set to "multiple" then allows a user to select multiple items from the menu.
Button Controls
There are various ways in HTML to create clickable buttons. You can also create a clickable button using inputtag by setting its type attribute to button. The type attribute can take the following values −
Sr.No Type & Description
1 submit
This creates a button that automatically submits a form.
2 reset
This creates a button that automatically resets form controls to their initial values.
3 button
This creates a button that is used to trigger a client-side script when the user clicks that button.
4 image
This creates a clickable button but we can use an image as background of the button.