HTML Element: <form>
[this page | pdf | back links]
The
HTML <form> element indicates an HTML
form for user input. Typically, a <form>
element will contain one or more of the following form elements:
-
<button>
-
<fieldset>
-
<input>
-
<label>
-
<optgroup>
-
<option>
-
<select>
-
<textarea>
The attributes it can take
(other than HTML
global attributes and HTML event attributes)
include:
Attribute
|
Description
|
More
|
accept-charset
|
Specifies character
encodings used for form submission
|
Here
|
action
|
Where to send form-data
when form submitted
|
Here
|
autocomplete
|
Specifies whether
element has autocomplete enabled
|
Here
|
enctype
|
How form-data to be
encoded when submitted to server
|
Here. Only for
method = post
|
method
|
Specifies HTTP method
used when sending form-data
|
Here
|
name
|
Name of element
|
Here
|
novalidate
|
Form should not be
validated when submitted
|
Here
|
target
|
Specifies where / how
to open the linked document (or where to submit the form)
|
Here
|
It also used to take the
accept attribute, but this is no longer supported in HTML 5.
To create or access such
an element in JavaScript
see here. The
corresponding HTML DOM
object supports standard
DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above
(with the novalidate property of
the underlying element corresponding to the noValidate
property of the DOM object). It also supports the following additional
properties and methods:
Additional properties:
Property
|
Description
|
More
|
encoding
|
An alias for enctype
|
Here
|
length
|
Returns number of
elements in form
|
Here
|
Additional properties:
Method
|
Description
|
More
|
reset()
|
Resets form
|
Here
|
submit()
|
Submits form
|
Here
|
The default style
applicable to this element is shown here.
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
Created using HTML:<br>
<form action="http://www.nematrian.com/ExpressionEvaluator.aspx">
Evaluate: <input type="text" name="expr" value="3*5"><input type="submit" value="Go to webpage to evaluate">
</form>
<br><br>Created using JavaScript:<br>
<span id="element"></span>
<script>
var f = document.createElement("FORM");
f.setAttribute("action","http://www.nematrian.com/ExpressionEvaluator.aspx");
var x1 = document.createElement("INPUT");
x1.setAttribute("type","text"); x1.setAttribute("name","expr");
x1.setAttribute("value","3*5");
var x2 = document.createElement("INPUT");
x2.setAttribute("type","submit");
x2.setAttribute("value","Go to webpage to evaluate");
var txt = document.createTextNode("Evaluate: ");
f.appendChild(txt);
f.appendChild(x1);
f.appendChild(x2);
document.getElementById("element").appendChild(f);
</script>
</body>
</html>
|
NAVIGATION LINKS
Contents | Prev | Next | HTML Elements