Reputation: 63
I've got the script for checking if an input isn't empty. It works in Firefox, but if I switch to Chrome or IE, button is enabled even if I submit an empty string. Does anybody know any solution for this issue?
$(document).ready(function(){
$('.comment_button').attr('disabled',true);
$('.comment_input').keyup(function(){
if ($.trim($(this).val()).length != 0) {
$('.comment_button').attr('disabled', false);
}
else
{
$('.comment_button').attr('disabled', true);
}
})
});
Upvotes: 0
Views: 408
Reputation: 133433
There is a typo in your code '
is missing after selector
Use $('.comment_input')
instead of $('.comment_input)
In line
$('.comment_input).keyup(function(){
Edit: use .prop() instead of .attr()
Working code JS:
$('.comment_button').prop('disabled', true);
$('.comment_input').keyup(function () {
$('.comment_button ').prop('disabled', $.trim($(this).val()).length == 0);
});
HTML:
<input type="text" class="comment_input" name="somethng"/>
<button class="comment_button">something</button>
Upvotes: 4