Button not getting disabled?


#1

<script>
$(document).ready(function(){
$(".btn").click(function(){
	var post=$('.status-box').val();
	$("<li>").text(post).prependTo(".posts");
	$('.status-box').val('');
	$('#counter').text(140);
});

 $('.status-box').keyup(function() {
    var Length=$(this).val().length;
    var charLeft=140-Length;
    if(charLeft==140){
    	$(".btn").addClass("disabled");
    }
    else if(charLeft<0){
    	$(".btn").addClass("disabled");
    }
    else{
    	$(".btn").removeClass("disabled");
    }

        
  });
});
</script>

<body>
<form>
<textarea rows="4" cols="67" placeholder="Whats's on your mind ?" class="status-box"></textarea>
<a class="btn" href="#">Post</a><a class="btn1" id="counter">140</a>

<div class="container">
<ul class="posts">

</ul>
</div></form>
</body>

#2

Hi @manojselvin,

After the $('.status-box').keyup(...); part, you need a line that adds the disabled class to .btn, so that the button gets disabled before you do anything :slight_smile:


#3

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.