admin管理员组文章数量:1430130
I've searched for the answer to this problem but still can't get this to work:
<script type="text/javascript">
$(document).ready(function (){
validate();
$('#contact_subject').change(validate);
});
function validate(){
if ($('#contact_subject').val().length > 0 {
$('button').prop('disabled', false);
}
else {
$('button').prop('disabled', true);
}
}
</script>
I want to make sure #contact_subject
has data or else disable the button.
I've searched for the answer to this problem but still can't get this to work:
<script type="text/javascript">
$(document).ready(function (){
validate();
$('#contact_subject').change(validate);
});
function validate(){
if ($('#contact_subject').val().length > 0 {
$('button').prop('disabled', false);
}
else {
$('button').prop('disabled', true);
}
}
</script>
I want to make sure #contact_subject
has data or else disable the button.
2 Answers
Reset to default 5I think you are missing a bracket ) in if condition
function validate(){
if ($('#contact_subject').val().length > 0) {
$('button').prop('disabled', false);
}
else {
$('button').prop('disabled', true);
}
}
Change the event.Try this: http://jsfiddle/e0t7qv56/1/
$("#field").keyup(function(){
console.log($(this).val().length);
if($(this).val().length)
$("#btn").prop('disabled', false);
else
$("#btn").prop('disabled', true);
});
本文标签: javascriptDisable button until required fields are validStack Overflow
版权声明:本文标题:javascript - Disable button until required fields are valid - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745456232a2659113.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论