How can you disable the send -button if there is one or more input -fields empty?
My attempt in pseudo-code
if ( $("input:empty") ) {
$("input:disabled")
}
else
// enable the ask_question -button
I have been reading these articles without finding a right solution
I use at the moment the following code.
It contains one bug about the character ;
, but I cannot find it.
$(document).ready(function(){
$("#ask_form").validate(){
rules: {
username {
required: true,
minlenghth: 2
},
email: {
required: true;
minlength: 6
},
password {
required: true,
minlength: 6
}
}
});
}
I slighhtly modified Meder's code. It disables the send
-button permanently so it has a bug too.
$(document).ready(function(){
var inputs = $('input', '#ask_form'), empty = false;
// can also use :input but it will grab textarea/select elements and you need to check for those..
inputs.each(function() {
if ( $(this).val() == '' ) {
empty = true;
return;
}
});
if ( empty ) {
$('.ask_question').attr('disabled', 'disabled'); // or true I believe.
}
});
var $submit = $("input[type=submit]");
if ( $("input:empty").length > 0 ) {
$submit.attr("disabled","disabled");
} else {
$submit.removeAttr("disabled");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With