根据密码输入长度启用/禁用按钮使用JavaScript
尝试根据密码输入长度启用/禁用表单按钮,但我的代码不起作用。如果长度小于15个字符的按钮应禁用。
到目前为止
<form class="form" id="form1" method="POST" action="submit.php" accept-charset="UTF-8" autocomplete="off">
<input type="password" placeholder="Password" id="passfield">
<button type="submit" id="form-submit">CONNECT</button>
</form>
function submit_btn() {
var field = document.getElementById("passfield");
var button = document.getElementById("form-submit");
if (field.value.lenght < 15){
button.setAttribute("disabled", "");
}else{
button.removeAttribute("disabled");
}
};
Trying to enable/disable a form button based on password input length but my code doesn't work. If the length is less than 15 characters button should be disabled.
So far my simple html form
<form class="form" id="form1" method="POST" action="submit.php" accept-charset="UTF-8" autocomplete="off">
<input type="password" placeholder="Password" id="passfield">
<button type="submit" id="form-submit">CONNECT</button>
</form>
No username field needed in my case
and so far my Javascript code
function submit_btn() {
var field = document.getElementById("passfield");
var button = document.getElementById("form-submit");
if (field.value.lenght < 15){
button.setAttribute("disabled", "");
}else{
button.removeAttribute("disabled");
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在哪里致电submit_btn?
另外拼写长度
是更好的版本
Where do you call submit_btn?
Also spelling length
Here is a better version