Javascript examples for DOM HTML Element:Input Password
The required property sets or gets whether a password field must be filled out before submitting a form.
This property reflects the HTML required attribute.
Set the required property with the following Values
Value | Description |
---|---|
true|false | Sets whether a password field is required. |
A Boolean, returns true if the password field is a required part of form submission, otherwise it returns false
The following code shows how to check if a password field must be filled out before submitting a form:
<!DOCTYPE html> <html> <body> <form action="#"> Password: <input type="password" id="myPsw" name="usr_psw"> <input type="submit"> </form>//from ww w . ja va2 s.c o m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var v = document.getElementById("myPsw").required; document.getElementById("demo").innerHTML = v; } </script> </body> </html>