<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> </div> </nav> <div class="col-md-6 well"> <hr style="border-top:1px dotted #ccc;"/> <div class="col-md-5"> <form> <div class="form-group"> <input type="text" id="username" class="form-control"/> </div> <div class="form-group"> <input type="password" class="form-control" id="password" onkeyup="passwordValidate(this)"/> </div> </form> </div> </div> </body> </html>
function passwordValidate(input){ var chk_length = document.getElementById('chk_length'); var bool_length; var password = input.value; if(password.length > 12){ chk_length.removeAttribute('class'); chk_length.setAttribute('class', 'alert-success'); chk_length.innerHTML = "✔ Password must be a 12 characters long"; bool_length = true; }else{ chk_length.removeAttribute('class'); chk_length.setAttribute('class', 'alert-danger'); chk_length.innerHTML = "X Password must be a 12 characters long"; bool_length = false; } if(bool_length){ document.getElementById('login').removeAttribute('disabled'); }else{ document.getElementById('login').setAttribute('disabled', 'disabled'); } } function userLogin(){ var username=document.getElementById('username').value; var password=document.getElementById('password').value; if(username==""){ alert("Username must not be empty"); }else{ alert("You have login!"); window.location='index.html'; } }