javascript - Input value disables Enter key -


i have annoying problem ever! i'm using easy use password script:

var count = 2;  function validate() {     var un = document.myform.username.value;     var pw = document.myform.pword.value;     var valid = false;      var unarray = ["natalie"];      var pwarray = ["0123456"];       (var = 0; < unarray.length; i++) {         if ((un == unarray[i]) && (pw == pwarray[i])) {             valid = true;             break;         }     }      if (valid) {         window.location = "hello.html";     } else {         alert("errr! wrong!");         document.myform.username.value = "";         document.myform.pword.value = "";         document.myform.username.disabled = true;         document.myform.pword.disabled = true;         return false;     }  } 

now, have done form script:

<form method="post" onsubmit="return validate()" name="myform">     <input type="text" value="natalie" name="username" style="width:0px;height:0px;border:0px solid;background:rgba(00,00,00,0);">     <input type="text" name="pword" style="width:150px;border:1px solid #fff;font-family:roboto;font-size:12px;padding:1% 12%;text-align:center;letter-spacing:4px;font-weight:900;margin:2%;" value="ex: 354627" onfocus="if (this.value == 'ex: 354627')     {this.value=''}">     <br>     <input name="submit" type="submit" value="check in" onclick= " validate()"> </form> 

eveything works, except of typing in password , pressing enter key!

why , how fix it? took time put in jsfiddle!

http://jsfiddle.net/j9hfg/14/

your onclick event needs have return before validate(). input type needs submit submit button. enable enter key.

<input name="submit" type="submit" value="check in" onclick= "return validate()"> 

i might instead make onsubmit event on form

<form method="post" onsubmit="return validate()" name="myform"> 

the return required because if substitute return value onclick="false", click event still propagates. if return false onclick="return false" event stops.

also very importantly, usernames , password should not in javascript. please server-side.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -