Latest web development tutorials

HTML DOM Form elements set

Form Object Reference Form Object

Definition and Usage

elements set returns an array of all the elements form form.

grammar

formObject.elements[].property


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support elements set


Examples

Examples

Returns the value of each element form form:

<html>
<body>

<form id="frm1" action="form_action.html">
First name: <input type="text" name="fname" value="Donald"><br>
Last name: <input type="text" name="lname" value="Duck"><br>
<input type="submit" value="Submit">
</form>

<script>
var x=document.getElementById("frm1");
for (var i=0;i<x.length;i++)
{
document.write(x.elements[i].value);
document.write("<br>");
}
</script>

</body>
</html>

Examples of the above output:

Donald
Duck
Submit

try it"


Form Object Reference Form Object