在提交密码时检查密码 [英] Checking Password onsubmit

查看:164
本文介绍了在提交密码时检查密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的注册表单:

 < form action =addusermethod =postonsubmit =' passwordCheck()'> 
电子邮件地址:< input type =emailname =emailrequired autocomplete =onplaceholder =fr@star.com/>< br />
用户名:< input type =textname =usernamemaxlength = 25 required placeholder =JoyfulSophia/>< br />
密码:< input type =passwordname =passwordid ='password'onkeydown ='checkPassword()'maxlength = 30 required placeholder =**********/ >
Password(Again):< input type ='password'id ='pass_repeat'/>
< br />
< br />
< input type =submitvalue =Send/> < input type =reset>
< / form>因此,当表单被提交时,它会调用passwordCheck(),它会根据易猜测的密码对其进行测试,不重复相同的密码等。它将错误(如果有的话)放在< p> 中(未显示)。 checkPassword()工作,错误显示正确,但表单仍然提交,而我读过的JS文档说,如果onsubmit返回false,表单不应该提交。



checkPassword()返回false时为什么提交表单?此外,checkPassword()不会在密码输入中的每个按键上被调用。

它需要是

 < form ... onsubmit =return passwordCheck();> 

至于onkeydown,请检查您的checkPassword()函数实际上是否被调用。让它做一个alert()或类似的东西。


I have a basic signup form:

<form action="adduser" method="post" onsubmit='passwordCheck()'>
    Email Address: <input type="email" name="email" required autocomplete="on" placeholder="fr@star.com"/><br/>
    Username: <input type="text" name="username" maxlength=25 required placeholder="JoyfulSophia"/><br/>
    Password: <input type="password" name="password" id='password' onkeydown='checkPassword()' maxlength=30 required placeholder="**********" />
    Password (Again): <input type='password' id='pass_repeat'/>
    <br/>
    <br/>
    <input type="submit" value="Send" /> <input type="reset">
</form>

So when the form is submitted, it calls passwordCheck(), which tests it against easily guessable passwords, not repeating the same password etc. It puts the error, if any, in a <p> (not shown). checkPassword() works and the error is displaying correctly, but the form still submits while JS docs that I've read say that if onsubmit returns false, the form should not submit.

Why is the form submitting when checkPassword() returns false? Also, checkPassword() is not being called on each keystroke in the passwords input.

解决方案

It needs to be

<form ... onsubmit="return passwordCheck();">

as for the onkeydown, check that your checkPassword() function is actually being called. have it do an alert() or something similar.

这篇关于在提交密码时检查密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆