javascript - Jquery script for checking if input is not empty. A space button issue -
i've script, validates if input not empty. works, problem appears if click space button. enables button, , allows send empty input. wonder, guys, possible upgrade script , fix issue?
the script:
$(document).ready(function(){ $('.post_button').attr('disabled',true); $('.message').keyup(function(){ if($(this).val().length !=0){ $('.post_button').attr('disabled', false); } else { $('.post_button').attr('disabled', true); } }) });
trim value using trim() , check length if don't want send spaces.
$(document).ready(function () { $('.post_button').attr('disabled', true); $('.message').keyup(function () { if ($.trim($(this).val()).length != 0) { $('.post_button').attr('disabled', false); } else { $('.post_button').attr('disabled', true); } }) }); use $.trim($(this).val()) $(this).val().trim() doesn't work in ie8.
Comments
Post a Comment