<html>
<body>
<form id="myForm">
Name: <input type="text" id="myText" value="Mickey">
</form>
<p>Click the "Try it" button to display the id of the form the text field belongs to.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myText").form.id;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html