html - Simple Javascript login form -
<form id="loginform"> <p id="usernamelabel">username:</p> <input type="text" name="username" id="username" placeholder="username"/><br> <p id="passwordlabel">password: </p> <input type="password" name="password" id="password" placeholder="password"/><br> <input id="loginbutton" type="submit" value="login!" onsubmit="validateform()"> </form> <p id="loginmessage">please login!</p> <script type="text/javascript"> function validateform() { var united nations = document.loginform.username.value; var pw = document.loginform.password.value; var username = "mitchwardle"; var password = "123abc456"; if ((un == username) && (pw == password)) { window.location = "content.html"; homecoming false; } else { alert ("login unsuccessful, please check username , password"); } } </script>
i have created little login form on javascript , want navigate content.html when username , password right when click login button removes text text box's, can see whats wrong?
you need homecoming false prevent default action of submitting form , page gets refresh andyou loss data, can set type of submit button to
type="button"
or can alter onsubmit
onclick="validateform(); homecoming false; "
javascript html html5 forms login
No comments:
Post a Comment