Javascript DOM HTML Input Text form Property

Introduction

Return the id of the form containing the <input type="text"> element:

var x = document.getElementById("myText").form.id;

Click the button to display the id of the form the text field belongs to.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm">
  Name: <input type="text" id="myText" value="Mickey">
</form>/*  w w w . ja  v  a2 s .c o  m*/
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("myText").form.id;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related