how to show a live updated character count of textbox in page with javascript?

1
=
0
+
1
1 Bitcoin bounty has been announced by author.
0 has been already awarded by author.
1 remains available.
1

I want to show the user how many characters they have typed in the text box.

1 Answer

1
=
1
=
$0.95
1 tip with total amount of 4.3 mBTC($0.95 USD) have been sent by alex

Pretty simple solution, with a few assumptions: 1. you load javascript functions 2. users have modern browsers

On the text box use this code: onkeyup="charcountupdate(this.value)"

After the text box, add this where you want to display the counter: <span id=charcount></span>

(can also use div instead of span)

And on the javascript file add these lines:

function charcountupdate(str){
var lng = str.length;
document.getElementById("charcount").innerHTML = lng + ' out of xxx characters';
}

see my example: http://codepen.io/borisplotkin/pen/RPwXeK

Hope this helps.

SEND BITCOIN TIPS
User rating:

Boris, thanks again, sending you some coins right now!

1

Too many commands? Learning new syntax?

FavScripts.com is a free tool to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.

Boost your productivity with FavScripts.com!

Post Answer