HTML <form> tagS2C Home « HTML <form> tag
Definition
The <form> tag is used to define a form whose user input information is sent to the URL specified in the required action attribute.
Example
<form action="../../htmlintermediate/simpleform.html" method="get">
<p>Name:<input type="text" name="name"></p>
<p>Which pie do you prefer?:</p>
<p><input type="radio" name="pie" checked="checked" value="chicken"> Chicken</p>
<p><input type="radio" name="pie" value="fish"> Fish</p>
<p><input type="radio" name="pie" value="shepherds"> Shepherds</p>
<p>Other stuff you wanna tell us about pies:</p>
<p><textarea rows="3" cols="30" name="comments"></textarea></p>
<p>Submit your information:</p>
<p><input type="submit" value="Submit"></p>
</form>
Attributes
The following attributes can be used with the <form> tag.
Attribute | Value | Description | Example |
---|---|---|---|
accept- | character_ | A space-separated list of one or more character encodings that the server accepts on form submission. Default UNKNOWN |
|
action | url | Specifies the url of a file that will process the control on submission. |
|
auto | empty string or auto | Specifies whether the form should complete the form contents based on user history. |
|
enctype | application/x multipart/form-data text/plain | Specifies how form-data should be encoded before sending it to a server. |
|
method | get post | Specifies the HTTP method to be used on control submission. |
|
name | name | Specifies a name for the button. |
|
no | empty string or novalidate | Specifies that no validation is to be done on control submission. |
|
rel | Specifies the relationship between a linked resource and the current document. |
| |
external | Referenced document is not part of the same site as current document. | ||
help | Link to a help document for current context. | ||
license | Referenced document provides the copyright license terms for current document. | ||
next | Indicates that the document is part of a sequence, and that the link to the referenced document is next. | ||
nofollow | Indicates that the link is not endorsed by the original author or publisher of the page. | ||
noopener | Creates a top-level browsing context that is not an auxiliary browsing context if the hyperlink would create either of those to begin with. | ||
noreferrer | Indicates that no referrer information is to be leaked when following the link. | ||
opener | Creates an auxiliary browsing context if the hyperlink would otherwise create a top-level browsing context that is not anauxiliary browsing context. | ||
prev | Indicates that the document is part of a sequence, and that the link to the referenced document is previous. | ||
search | Specifies that referenced document provides an interface specifically for searching the document and its related resources. | ||
target | Specifies where to display the response after control submission. |
| |
_blank | Opens linked document in new window or tab. | ||
_parent | Opens linked document in parent frame. | ||
_self (default) | Opens linked document in same frame as it was clicked in. | ||
_top | Opens linked document in window body | ||
frame | Opens the linked document in a named framename. |
Attribute | Description | Example |
---|---|---|
Common | ||
class | Specifies a classname for the element allowing you to apply the style of the predefined class to the content. |
|
id | Specifies a unique id for the element allowing you to apply the style of the predefined id to the content. |
|
style | Specifies an inline style for the element allowing you to apply the style to the contentt. |
|
title | Specifies an inline style for the element allowing you to apply the style to the content. |
|
Keyboard | ||
accesskey | Specifies a keyboard shortcut to associate with the element. |
|
tabindex | Specifies a tab order for the element. |
|
Language | ||
dir | Specifies the directional flow of the content. |
|
lang | Specifies a language code for the content of the element. |
|
spell | Specifies an inline style for the element allowing you to apply the style to the contentt. |
|
translate | Specifies an inline style for the element allowing you to apply the style to the content. |
|
Miscellaneous | ||
content | Specifies whether the content of the element is editable. |
|
draggable | Specifies whether the element is draggable. |
|
hidden | Specifies whether the element is not yet, or no longer, relevant. |
|
Attribute | Description | Example |
---|---|---|
Document Element | ||
oncopy | The script to be run when the user copies the content of an element. |
|
oncut | The script to be run when the user cuts the content of an element. |
|
onpaste | The script to be run when the user pastes some content into an element. |
|
Drag and Drop | ||
ondrag | The script to be run when an element is dragged. |
|
ondragend | The script to be run when an element has stopped being dragged. |
|
ondrag | The script to be run when an element has been dragged to a valid drop target. |
|
ondrag | The script to be run when an element leaves a valid drop target. |
|
ondragover | The script to be run when an element is being dragged over a valid drop target. |
|
ondrag | The script to be run at the start of a drag operation. |
|
ondrop | The script to be run when a dragged element is being dropped. |
|
Form | ||
onblur | The script to be run when the element loses focus. |
|
onchange | The script to be run when object changed and attempt to leave field. |
|
oncontext | The script to be run when a context menu is triggered. |
|
onfocus | The script to be run when the element gets focus. |
|
oninput | The script to be run when an element gets user input. |
|
oninvalid | The script to be run when an element is invalid. |
|
onreset | The script to be run when a dragged element is being dropped. |
|
onselect | The script to be run when some or all of the contents of an object are selected. |
|
onsubmit | The script to be run when a form is submitted. |
|
Keyboard | ||
onkeydown | The script to be run when an element is in focus and keyboard key is pressed down. |
|
onkeypress | The script to be run when an element is in focus and keyboard key is pressed down and released. |
|
onkeyup | The script to be run when an element is in focus and keyboard key is released. |
|
Media | ||
onabort | The script code to be run on abort. |
|
oncanplay | The script to be run when a file has buffered enough so it is ready to start playing. |
|
oncanplay | The script to be run when a file can be played all the way to the end without further need of buffering. |
|
oncue | The script to be run when the cue changes when using the track element. |
|
onduration | The script to be run when the length of the media is changed. |
|
onemptied | The script to be run when a media resource element suddenly becomes empty, usually due to an error. |
|
onended | The script to be run when the media has reach the end. |
|
onloaded | The script to be run when media data is loaded and playback can start. |
|
onloaded | The script to be run when metadata has been loaded. |
|
onload | The script to be run whenthe media resource has started loading. |
|
onpause | The script to be run when the media resource has been paused. |
|
onplay | The script to be run when the media resource starts playback. |
|
onplaying | The script to be run when when playback has already begun. |
|
onprogress | The script to be run when the browser is fetching the media data. |
|
onrate | The script to be run when the playback rate changes. |
|
onseeked | The script to be run when the seeking attribute is set to false indicating that seeking has finished. |
|
onseeking | The script to be run when the seeking attribute is set to true indicating that seeking is currently active. |
|
onstalled | The script to be run when the browser is unable to continue fetching media data. |
|
onsuspend | The script to be run when media data has stopped before being completely loaded. |
|
ontime | The script to be run when the media resources current playback position has changed. |
|
onvolume | The script to be run when the volume has changed or been muted. |
|
onwaiting | The script to be run when the media resource has paused but is expected to resume. |
|
Mouse | ||
onclick | The script to be run when when a mouse is clicked on an element. |
|
ondblclick | The script to be run when a mouse is double clicked on an element. |
|
onmouse | The script to be run when he mouse button is pressed down while the cursor is over an element. |
|
onmouse | The script to be run when the mouse button is moved. |
|
onmouseout | The script to be run when the mouse cursor moves off an element. |
|
onmouse | The script to be run when the mouse cursor moves over an element. |
|
onmouseup | The script to be run when the mouse button is released while the cursor is over the element. |
|
onwheel | The script to be run when the mouse wheel rolls up or down over an element. |
|
Scroll | ||
onscroll | The script code to be run when the scrollbar of an element is being scrolled. |
|
Window - NONE |