Create a simple javascript character counter

Posted by Andi Syahputra | 11:11 PM
Just sharing to you a simple javascript character counter that counts every input character in realtime. When you enter any character in input box, the script will count the total character you entered after you release keyboard press (onkeyup event), then display the number of character you typed.

Let's try it yourself. Here is the HTML code, paste it to blank HTML document and you're ready to go.. :D
You can also apply this small utility to your project or webpage.

<title>Character counter</title>
<form method="POST">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<textarea rows="30" name="charcount" cols="160" wrap="virtual" onkeyup="countit(this)"></textarea>
</td>
</tr>
<tr>
<td width="100%"><div align="right"><p>Jumlah karakter: <input type="text" name="displaycount" size="20" readonly="readonly"></p>
</td>
</tr>
</table>
</form>
<script language="JavaScript">
function countit(what){
formcontent=what.form.charcount.value
what.form.displaycount.value=formcontent.length
}
</script>
hi folks, visit my other tutorial blog at Kumpulan tutorial menarik
0 comments