Solved

javascript count up but cant count down

Posted on 2011-09-23
9
291 Views
Last Modified: 2012-05-12
  $(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
0
Comment
Question by:runnerjp2005
  • 4
  • 3
  • 2
9 Comments
 
LVL 40

Expert Comment

by:gurvinder372
Comment Utility
what is the above code is trying to do?
0
 
LVL 17

Expert Comment

by:sonawanekiran
Comment Utility
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

0
 

Author Comment

by:runnerjp2005
Comment Utility
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
0
 

Author Comment

by:runnerjp2005
Comment Utility
also i need to turn the txt red below 0 to alert the user!
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 40

Expert Comment

by:gurvinder372
Comment Utility
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");
                                                }
                                            });
                                        });  
0
 
LVL 40

Expert Comment

by:gurvinder372
Comment Utility
 $(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");
                                                }
                                            });
                                        });  
0
 
LVL 17

Expert Comment

by:sonawanekiran
Comment Utility
Just add below code in else part

$('#count').html(count);
$(". submit").attr("disabled",true);
0
 

Author Comment

by:runnerjp2005
Comment Utility
 $('#count').html("count reached 0 now");  - how do i chnage this to minuses?
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
Comment Utility
$(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 " + count );
                                                    $('#count').css("color", "red");
                                                }
                                            });
                                        }
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now