/    Sign up×
Community /Pin to ProfileBookmark

JS Character Countdown (photo)

Hi, i am trying to find a good JS character countdown script that i can use to count down the characters remaining in a text area field that i am using on my site.

I have done a lot of searching on google but a lot of them seem to have very long scripts and others scripts are over 6 years ago.

Can someone recommend a good, robust character countdown timer that works very well and does not require a lot of resources when it is running. I was hoping to find something similar to the twitter script (please see below)

[IMG]http://i796.photobucket.com/albums/yy242/oo7ml/ScreenShot2012-03-11at125156.png[/IMG]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@007JulienMar 11.2012 — The principle of a character counter can be illustrated as follows:
[CODE]<body onload="cntr(document.getElementById('txa').value)">
[COLOR="Blue"]<!-- HTML - A textarea for inputs and a paragraph to display the results-->[/COLOR]
<textarea id="txa" onkeyup="cntr(this.value)"></textarea>
<p id="cnt"></p>

<script type="text/javascript">
[COLOR="Blue"]// Javascrip - A function called with onkeyup and onload events (see supra)[/COLOR]
function cntr(txtStr){
[COLOR="Blue"]// The length of the string[/COLOR]
var nmbChr=txtStr.length;
[COLOR="Blue"]// The length of the split array with care of spaces...[/COLOR]
var nmbWrd=txtStr.replace(/^s+|s+$/g,'').split(/s+/g).length;
document.getElementById('cnt').innerHTML='This text contains '+nmbChr+' character'+(1<nmbChr?'s':'');
document.getElementById('cnt').innerHTML+='<br>and '+nmbWrd+' word'+(1<nmbWrd?'s':'');
}
</script>
</body>
[/CODE]
We remove spaces at the beginning and at the end of the string and split it with one or more spaces to count the words. Then it would be possible to make differences with the maximal character or word numbers...
Copy linkTweet thisAlerts:
@oo7mlauthorMar 11.2012 — cool, thanks for your help...
×

Success!

Help @oo7ml spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...