Get the id of the form containing the <input type="password"> element:
var x = document.getElementById("myPsw").form.id;
Click the button to display the id of the form the password field belongs to.
<!DOCTYPE html> <html> <body> <form id="myForm"> Password: <input type="password" id="myPsw"> </form>// w w w .j ava2 s . c om <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myPsw").form.id; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The form property returns a reference to the form that contains the password field.
This property returns a form object on success.
This property is read only.
If the password field is not in a form, null is returned