admin管理员组文章数量:1434363
I know there is a lot answers for that out-there, but from some reason it not working for me.
You can view the code on JSFiddle
There is mistake on the position of the script? with one of the inputs id ?
The problem: after fill the text fields, the button still disabled.
HTML
<form class="form" name="contactform" method="post" action=".php">
<input placeholder="Your Name*" type="text" name="name" maxlength="50">
<input placeholder="Phone *" type="text" name="telephone" maxlength="30">
<input placeholder="Email *" type="email" name="email" maxlength="80">
<input class="send" id="register" type="submit" value="Send" disabled="disabled">
<p>* = Requierd fields</p>
</form>
JQUERY ON HEAD
<script src=".11.1/jquery.min.js"></script>
<script>
(function() {
$('form > input').keyup(function() {
var empty = false;
$('form > input').each(function() {
if ($(this).val() === '') {
empty = true;
}
});
if (empty) {
$('#register').attr('disabled', 'disabled');
} else {
$('#register').removeAttr('disabled');
}
});
})();
</script>
I know there is a lot answers for that out-there, but from some reason it not working for me.
You can view the code on JSFiddle
There is mistake on the position of the script? with one of the inputs id ?
The problem: after fill the text fields, the button still disabled.
HTML
<form class="form" name="contactform" method="post" action="https://lp.outit.co.il/LA-FACE/send_form_email.php">
<input placeholder="Your Name*" type="text" name="name" maxlength="50">
<input placeholder="Phone *" type="text" name="telephone" maxlength="30">
<input placeholder="Email *" type="email" name="email" maxlength="80">
<input class="send" id="register" type="submit" value="Send" disabled="disabled">
<p>* = Requierd fields</p>
</form>
JQUERY ON HEAD
<script src="http://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
(function() {
$('form > input').keyup(function() {
var empty = false;
$('form > input').each(function() {
if ($(this).val() === '') {
empty = true;
}
});
if (empty) {
$('#register').attr('disabled', 'disabled');
} else {
$('#register').removeAttr('disabled');
}
});
})();
</script>
Share
Improve this question
asked Jun 1, 2014 at 8:51
OshribOshrib
1,90013 gold badges42 silver badges69 bronze badges
2
- Your fiddle is working properly as expected .Whats the problem?Form is not submitting till i fill data.Its ok.Whats wrong? – Pratik Joshi Commented Jun 1, 2014 at 8:54
- How its working? for me after fill the text fields, the button still disabled. – Oshrib Commented Jun 1, 2014 at 8:55
3 Answers
Reset to default 3I posted working fiddle ,Is this what u want ? http://jsfiddle/qqwcu/2/
Note its preferred to use: $('#register').prop("disabled", false);
Check this Remove disabled attribute using JQuery?
$(document).ready(function(){
$('form > input').keyup(function() {
var empty1 = false;
$('form > input').each(function() {
if ($(this).val() === '') {
empty1 = true;
}
});
if (empty1) {
$('#register').attr('disabled', 'disabled');
} else {
$('#register').prop("disabled", false);
}
});
});
Your fiddle is fine, although ,You havent included jQuery there. Did that solve the problem?
Your code is run, when the DOM is not yet ready.
Sor wrap it with
$(document).ready()
本文标签: javascripthow to disable submit button until form is filledStack Overflow
版权声明:本文标题:javascript - how to disable submit button until form is filled - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745635020a2667502.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论