Solved

progress bar with textarea issue

Posted on 2012-03-16
1
293 Views
Last Modified: 2012-03-16
i have successfully implemented the code for showing a progress bar to the textarea while typing, but it has one issue,

currently it works as whenever it reaches the end of the contents, it changes its color of progress bar...

currently all is working fine, my concern is if the remaining characters are left as less than 20, it should change another color as a warning sign to user

here is my code:

if some class needs to prepared to handle, plz guide thanks

var main = text_area_box.length * 100;
			var value= (main / max_numb_of_words);
			var count = max_numb_of_words - text_area_box.length;
			if(text_area_box.length <= max_numb_of_words)
			{
					$("#pbar").css("background","green");
				$('#count').html(count);
				$('#pbar').animate({"width": value+'%'}, 1);
			}
			else
			{
					$("#pbar").css("background","red");
				$("#textid").val(text_area_box.substr(0,max_numb_of_words));
			}

Open in new window



now here i also want to add a elseif block that if the textarea length left is low than 25, change color to darkred, so user should know that i have only few characters left

any guidance
0
Comment
1 Comment
 
LVL 11

Accepted Solution

by:
SANDY_SK earned 500 total points
ID: 37729156
change your if loop to

if(text_area_box.length <= max_numb_of_words)
{
        if(count <= 25){
	        $("#pbar").css("background","red");
        } else {
	        $("#pbar").css("background","green");
        }
	$('#count').html(count);
	$('#pbar').animate({"width": value+'%'}, 1);
}

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

746 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

9 Experts available now in Live!

Get 1:1 Help Now