Link to home
Start Free TrialLog in
Avatar of Member_2_5230414
Member_2_5230414

asked on

javascript count up but cant count down

  $(document).ready(function () {
                                            $("#textbox").keyup(function () {
                                                var box = $(this).val();
                                                var main = box.length * 100;
                                                var value = (main / 140);
                                                var count = 140 - box.length;
                                                if (box.length <= 140) {
                                                    $('#count').html(count);
                                                }
                                                else {
                                                HERE!!!
                                                }
                                            });
                                        });   

Open in new window


I can count down to 0 but how can i continue to count down into the minus and

-1
-2
-3
-4 ect
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

what is the above code is trying to do?
You don't need if else part
$(document).ready(function () {
  $("#textbox").keyup(function () {
    var box = $(this).val();
    var main = box.length * 100;
    var value = (main / 140);
    var count = 140 - box.length;
    $('#count').html(count);
  });
});  

Open in new window

Avatar of Member_2_5230414
Member_2_5230414

ASKER

sonawanekiran:

with that code would there be any way of disabling my button <asp:Button Text="Submit" CssClass="submit" type="submit" id="Submit" value="Submit" runat="server" />
if the count goes under 0??

thats why i was going to use the else
also i need to turn the txt red below 0 to alert the user!
Hmmm...ok

  $(document).ready(function () {
                                            $("#textbox").keyup(function () {
                                                var box = $(this).val();
                                                var count = 140 - box.length;
                                                if (box.length <= 140) {
                                                    $('#count').html(count);
                                                }
                                                else {
                                                $(this).attr("readonly","readonly");
                                                }
                                            });
                                        });  
 $(document).ready(function () {
                                            $("#textbox").keyup(function () {
                                                var box = $(this).val();
                                                var count = 140 - box.length;
                                                if (count > 0) {
                                                    $('#count').html(count);
                                                }
                                                else {
                                                $(this).attr("readonly","readonly");
                                                    $('#count').html("count reached 0 now");
                                                    $('#count').css("color", "red");
                                                }
                                            });
                                        });  
Just add below code in else part

$('#count').html(count);
$(". submit").attr("disabled",true);
 $('#count').html("count reached 0 now");  - how do i chnage this to minuses?
ASKER CERTIFIED SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial