javascript - Validating form after error has been shown -



javascript - Validating form after error has been shown -

i have form username , password entered. if left blank error shown, when 1 of input box filled in , submit button clicked error that's there doesn't go away.

<script type="text/javascript"> function chck() { var valid = true; var pass = document.getelementbyid('password_box').value; var user = document.getelementbyid('username_box').value; if (user == '') { document.getelementbyid('password-error').innerhtml = "* please come in username proceed..."; document.getelementbyid('username_box').style.bordercolor = "#dc3d24"; document.getelementbyid('username_box').style.backgroundcolor = "maroon"; valid = false; } if (pass == '') { document.getelementbyid('user-error').innerhtml = "* please come in password proceed..."; document.getelementbyid('password_box').style.bordercolor = "#dc3d24"; document.getelementbyid('password_box').style.backgroundcolor = "maroon"; valid = false; }else{ valid = true; } homecoming valid; } </script> </head> <body> <form action="checkup.php" method="post" name="checkup"> <div class="login-box"> <input type="text" placeholder="username goes here.." id="username_box" class="box" name="username"> <input type="password" placeholder="password goes here.." id="password_box" class="box" name="password"> <br> <input type="submit" class="button" id="submit_button" value="logmein" onclick="return chck()"> <input type="button" class="button" id="clear_button" value="clear"> </div> </form> <br> <center> <div class="error-area" id="message"> <p id="password-error"> </p> <p id="user-error"> </p> </div> </center>

only if fill in both boxes, error goes away. want hide error 1 of boxes filled in text. help can give me.

try using html5......just add together required attribute , clear values utilize reset input

<form action="checkup.php" method="post" name="checkup"> <div class="login-box"> <input type="text" placeholder="username goes here.." id="username_box" class="box" name="username" required title="* please come in username proceed..."> <input type="password" placeholder="password goes here.." id="password_box" class="box" name="password" required title="* please come in password proceed..."> <br> <input type="submit" class="button" id="submit_button" value="logmein" onclick="return chck()"> <input type="reset" value="clear"> </div> </form>

or if want accomplish existing code seek using onfocus event clear error message. hope hepls

javascript html

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -