Avatar of Coast Line
Coast Line
Flag for Canada asked on

progress bar with textarea issue

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
JavaScriptAJAXJScript

Avatar of undefined
Last Comment
SANDY_SK

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
SANDY_SK

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61