Solved

javascript count up but cant count down

Posted on 2011-09-23
9
298 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
[X]
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
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

752 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