HTML Forms
HTML Forms
html
HTML Forms
❮ Previous Next ❯
First name:
Mickey
Last name:
Mouse
Submit
Try it Yourself »
<form>
.
form elements
.
</form>
file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 1/9
9/5/2019 dayframe.html
Form elements are different types of input elements, like text fields, checkboxes, radio buttons, submit
buttons, and more.
The <input> element can be displayed in several ways, depending on the typeattribute.
Type Description
<input type="text"> Defines a one-line text input field
<input type="radio"> Defines a radio button (for selecting one of many choices)
<input type="submit"> Defines a submit button (for submitting the form)
You will learn a lot more about input types later in this tutorial.
Text Input
<input type="text"> defines a one-line input field for text input:
file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 2/9
9/5/2019 dayframe.html
Example
<form>
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
</form>
Try it Yourself »
First name:
Last name:
Note: The form itself is not visible. Also note that the default width of a text field is 20 characters.
Example
file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 3/9
9/5/2019 dayframe.html
<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
Try it Yourself »
Male
Female
Other
The form-handler is typically a server page with a script for processing input data.
Example
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 4/9
9/5/2019 dayframe.html
First name:
Mickey
Last name:
Mouse
Submit
Normally, the form data is sent to a web page on the server when the user clicks on the submit button.
In the example above, the form data is sent to a page on the server called "/action_page.php". This page
contains a server-side script that handles the form data:
<form action="/action_page.php">
If the action attribute is omitted, the action is set to the current page.
file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 5/9
9/5/2019 dayframe.html
The default value is "_self" which means the form will be submitted in the current window.
To make the form result open in a new browser tab, use the value "_blank":
Example
Other legal values are "_parent", "_top", or a name representing the name of an iframe.
Example
file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 6/9
9/5/2019 dayframe.html
or:
Example
However, when GET is used, the submitted form data will be visible in the page address field:
/action_page.php?firstname=Mickey&lastname=Mouse
Notes on GET:
file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 7/9
9/5/2019 dayframe.html
Always use POST if the form data contains sensitive or personal information. The POST method does not
display the submitted form data in the page address field.
Notes on POST:
POST has no size limitations, and can be used to send large amounts of data.
Form submissions with POST cannot be bookmarked
If the name attribute is omitted, the data of that input field will not be sent at all.
This example will only submit the "Last name" input field:
Example
<form action="/action_page.php">
First name:<br>
<input type="text" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</form>
Try it Yourself »
file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 8/9
9/5/2019 dayframe.html
Example
<form action="/action_page.php">
<fieldset>
<legend>Personal information:</legend>
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
Try it Yourself »
file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 9/9