Document forms Collection namedItem(id) - Get the HTML content of the <form> element with id="myCarForm" in the document: - Javascript DOM

Javascript examples for DOM:Document forms

Description

Document forms Collection namedItem(id) - Get the HTML content of the <form> element with id="myCarForm" in the document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myCarForm">
  Favorite Car: <input type="text" name="fname" value="Volvo">
</form>//from  w w w.j  a  v  a2  s  .  c o m

<form id="myColorForm">
  Favorite Color: <input type="text" name="favcolor" value="Blue">
</form>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.forms.namedItem("myCarForm").innerHTML;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials