Set a password field to be a required part of form submission:
document.getElementById("myPassword").required = true;
Click the button to set the required property for the password field.
<!DOCTYPE html> <html> <body> <form action="/action_page.php"> Password: <input type="password" id="myPsw" name="usr_psw"> <input type="submit"> </form>/*from w ww .j a v a2s . co m*/ <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myPsw").required = true; document.getElementById("demo").innerHTML = "The required property was set."; } </script> </body> </html>