Character counter minus space bar

I have a character counter that has an absolute limit of 280 characters.  I have made it work to that spec, the only problem i have is that i need to exclude the spacebar as being counted as a character.  The user can only have 280 letters, but the spaces shouldnt count as one.  How would i fix it to where the spacebar wont be counted as a character?  Thanks for any help guys!!!
maxL=255;
function taLimit(taObj) {
	if (taObj.value.length==maxL) return false;
	return true;
}
 
function taCount(taObj,Cnt) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) objCnt.innerText=maxL-objVal.length;
	return true;
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}
 
html:
<textarea onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')" name="Description" rows=7 wrap="physical" cols=40>

Open in new window

chuckbeatsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hernst42Commented:
You can try:
objVal=taObj.value.replace(/\s/, '');
instead of just
objVal=taObj.value;
which will remove any whitespace from counting (if you only need the space, replace \s with a space
0
Lee SavidgeCommented:
Hi,

On the events I would call the replace function when evaluating string length. It may not be syntactically perfect but I'm not in a postition to try it yet but you get the idea.

Cheers,

Lee

maxL=255;
function taLimit(taObj) {
        if (taObj.value.length.replace(/ /g, '')==maxL) return false;
        return true;
}
 
function taCount(taObj,Cnt) { 
        objCnt=createObject(Cnt);
        objVal=taObj.value.replace(/ /g, '');
        if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
        if (objCnt) objCnt.innerText=maxL-objVal.length;
        return true;
}
function createObject(objId) {
        if (document.getElementById) return document.getElementById(objId);
        else if (document.layers) return eval("document." + objId);
        else if (document.all) return eval("document.all." + objId);
        else return eval("document." + objId);
}
 
html:
<textarea onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')" name="Description" rows=7 wrap="physical" cols=40>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chuckbeatsAuthor Commented:
The first suggestion was great, unfortunately after i hit the space bar once and then typed and hit the spacebar again, it would count it, but your solution didnt count it ever, thank you guys
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.