PHP scripts and programs for Beginner to Master

php programs, php ready to use scripts & functions, css tutorials, html, javascripts, ajax examples for Beginner to Master

Hello,
Today we will be seeing a javascript which will help us to show how many characters are remaining for a textbox or textarea,As soon as the user starts typing in a textbox or textarea, then we will show how many characters are remaining for entering into the textbox.

Here we are creating a simple textbox, and we are specifying the "maxlength" of the textbox to 20.





And "onKeyUp" event of the textbox we are calling a javascript function "countCharacters()".

we will be writing a standard function which accepts only some parameters and rest of the processing will be done in the function.

To this function we have to pass 3 parameters
1) id of the span - where counter will be shown when user types something
2) max_chars - length of the textarea which we specified in maxlength="20"
3) myelement - the id of the textbox where user types text

The function is as below





Now you can use this function anywhere, without a need to modify this function.

The full code to try out is here



Put a link back to our site, if you like this !

I'm reading: Javascript to show how many characters are remaining to enter in textbox or textareaTweet this!

3 comments:

very cool & good code, thank you very much for sharing.

Can you share this code on my JavaScript library?


Awaiting your response. Thank

hey this script is fine but it will not zero character remaining and did not stop after crossing the limit.....just check dis out

Hey Gagan, I checked the script and it works fine. Soon i will upload the demo of this example.

Post a Comment