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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -