troubleshooting Question

counting characters as progress bar

Avatar of Gurpreet Singh Randhawa
Gurpreet Singh RandhawaFlag for Canada asked on
13 Comments1 Solution373 ViewsLast Modified:
I found the following code and it is working perfectly fin, I am a noob in Javascript, so i want to change the code to work as for every character i count, it should count it and increase the progress bar, currently it is working but it shows the results in 5% increase everytime when i keep adding text,

So please guide me what i change here

function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
		var fieldWidth =  parseInt(field.offsetWidth);
		var charcnt = field.value.length;        
		// trim the extra text
		if (charcnt > maxlimit) { 
			field.value = field.value.substring(0, maxlimit);
		else { 
		// progress bar percentage
		var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
		document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
		document.getElementById(counter).innerHTML="Limit: "+percentage+"%"

	function setcolor(obj,percentage,prop){[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 13 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros