Character count / limit for InputTextArea in Visualforce pages

7:27 PM



Credits:  http://www.jqeasy.com/

In some cases, you might want to display a character count to notify the user that they can enter only a certain number of characters in  a text box in a Visualforce page.







There is a javascript file that you need to use to achieve the above behavior. The file was downloaded from jqeasy.com, i uploaded the file here in case you are not able to locate the file.

https://docs.google.com/file/d/0B5FQvDdE4z0PZU9JdC1mVk1BU28

STEP 1:

Download the file at https://docs.google.com/file/d/0B5FQvDdE4z0PZU9JdC1mVk1BU28 and upload it into Static Resources. Let's say we name the file as "CharCounter".

STEP 2:

Create a Visualforce Page with the code below.




Analyzing the code:

If you check the code, you could see that we have the 'styleclass' attribute specified for the inputtextarea's.

And this styleclass name is used in the document.ready() function to specify the character limits. You could use the 'id' attribute as well, but make sure you reference id's using the $Component notation.

4 comments

  1. Love this. Works like a charm. Thanks!

    ReplyDelete
  2. Please share the visuaforce page code

    ReplyDelete
  3. Thanks mate.
    This saved me hours of work.

    ReplyDelete
  4. How to implement it in Lightning.

    Thanks

    ReplyDelete

AD