Solved

javascript count up but cant count down

Posted on 2011-09-23
9
299 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
Suggested Courses

622 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