Javascript DOM HTML Input Email form Property

Introduction

Return the form's id where the <input type="email"> element is from:

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm">
  E-mail: <input type="email" id="myEmail">
</form>/*from   w w w  . j  a  v a  2  s  .com*/
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>

The form property returns a reference to the form containing the email field.

This property returns a form object on success.

This property is read only.




PreviousNext

Related