Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

javascript count up but cant count down

Posted on 2011-09-23
9
296 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
ID: 36586683
what is the above code is trying to do?
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36586691
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
ID: 36586745
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:runnerjp2005
ID: 36586753
also i need to turn the txt red below 0 to alert the user!
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36586767
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
ID: 36586777
 $(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
ID: 36586971
Just add below code in else part

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

Author Comment

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

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 36587604
$(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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

860 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