简体   繁体   中英

Check password when the return key is pressed?

The form below works, but only when the button is clicked. Can someone please tell me how to submit this form and check the password with the script below when the enter key is pressed as well?

 function checkPassword() { if (document.getElementById('password').value == 'abc123') { location.href = "./yes"; } else { location.href = "./no"; } }
 <div class="login-box"> <form> <div class="user-box"> <input type="password" id="password"> <label>PASSWORD</label> </div> <div class="gradient-button-container"> <input class="gradient-button" type="button" value="JOIN NOW" onclick="checkPassword()" /> </div> </form> </div>

You change type of input to "submit"

<input class="gradient-button" type="submit" value="JOIN NOW" onclick="checkPassword()" />

Moreover, remove onClick and add onSubmit event with checkPassword function on form tag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM