According to the condition post button should be disabled if there are no characters in the status box, but when we type a letter and delete it the post button remains enabled. . Please help with this!


#1



var main=function(){
    $('.btn').click(function(){
        var post=$('.status-box').val();
        $('<li>').text(post).prependTo('.posts');
        $('.status-box').val('');
        $('.counter').text('140');
        $('.btn').addClass('disabled')
        });
        $('.status-box').keyup(function(){
            var postLength=$(this).val().length;
            var charachtersLeft=140-postLength;
            $('.counter').text(charachtersLeft);
            if(charachtersLeft<0){
                $('.btn').addClass('disabled');
                }else if(charachtersLeft>140){
                     $('.btn').addClass('disabled');
                    }else{
                        $('.btn').removeClass('disabled');
                        }
            });
    };
$(document).ready(main);


#2

@netpro85044,

Try it by changing the mentioned ELSE-IF
into

else if(charachtersLeft>=140){
                     $('.btn').addClass('disabled');

#3

Hi!

You may try this:

else if(charachtersLeft==140){
     $('.btn').addClass('disabled');
}

As your condition will only execute when variable is greater than 140 and box area is set for 140 be default, you need to check if it's equal to 140. You could also check if it's equal or greater than 140 (charachtersLeft>=140)


#4

Hi thanks for that. But what i really need is that I can have up to 140 characters, in that case i should have my post button be disabled if the number of characters is less than 1 or greater than 140. The code works fine, but when I type a character the post button gets enabled (which is wright) but when i delete it, it should be disabled. But instead it stays enabled. So I want a code that can make it disabled when do the above...


#5

@netpro85044,
Then give us the FULL code
you are using now......


#6

@netpro85044 , I think you are having the same problem I had. Are you executing the first part of the exercise on disabling button post? Because the second half will disable the button after you post something.

eg.:
1) When you load the page and type nothing in text area, button is disabled.
2) If you type and erase everything without pressing the button, button returns to disabled status.
2) But, if you type and post, the next post you are able to post it blank.

If this is your case, please see my post below:

Otherwise, please show us full code with the evidence of your issue.