<!DOCTYPE html>
<html>
<body>
<form id="myCarForm">
Favorite Car: <input type="text" name="fname" value="Volvo">
</form>
<form id="myColorForm">
Favorite Color: <input type="text" name="favcolor" value="Blue">
</form>
<p>Click the button to display the name of each form element in the document.</p>
<button type="button" onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.forms;
var txt = "";
var i;
for (i = 0; i < x.length; i++) {
txt = txt + x[i].id + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>