• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Dynamically count/show/limit words in textarea

Dynamically count/show/limit words in textarea 11 years 1 month ago #26872

  • gham
  • gham's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
I was unable to find any reference to this aside from on-submission validation scripts:

Anyone know of a script (or method) that would allow dynamic (real-time) counting, displaying the count, and limiting words within a Textarea field/element? I see this all the time in forms in better Websites.

I'm trying to limit the number of words the user can input (length of message) to prevent users from pasting-in large amounts of text while minimizing the potential of the user being put-off too badly.

I know; you can't please all the people all the time!... just trying to "smooth the edges" so to speak.

Thanks for any help!
The administrator has disabled public write access.

Dynamically count/show/limit words in textarea 11 years 2 weeks ago #27262

  • jlewis500
  • jlewis500's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
  • Thank you received: 3
Hi,

Have just got solution to this by submitting support ticket, thought I would share:

Setting the character limit for a textarea is pretty easy, just follow instructions here www.rsjoomla.com/support/documentation/v...in-a-text-field.html

Above article link copied below for ease:

"How can I limit the Text area field to a preset number of characters?"

In order to limit the text area to a given number of characters you can consider using the following script in the Javascript section of your form:


<script type="text/javascript">
function rslimitText(limitNum) {
if (document.getElementById("area").value.length >= limitNum) {
document.getElementById("area").value = document.getElementById("area").value.substring(0, limitNum);
}
}
</script>


You will only have to change the value "area" with the name of the Text Area field from your form.

Also you will have to place a trigger for the above functions in the Additional Attributes section of your Text Area field:


onkeyup="rslimitText(20);"

OBVIOUSLY REPLACE THE 20 ABOVE WITH THE NUMBER OF CHARACTERS U WANT TO LIMIT FIELD TO.

THEN....GET THE COUNTER, LIKE THIS:

Please add a freetext element to your form. It should contain something like this:

<span id="tcounter">0</span>

Within your Javascript limit function (SEE ABOVE...), aftter this:

if (document.getElementById("area").value.length >= limitNum) {
document.getElementById("area").value = document.getElementById("area").value.substring(0, limitNum);
}

add:

document.getElementById('tcounter').innerHTML = document.getElementById("area").value.length;

It works! (Big thank you to Alexandru in Support)

I actually inserted <span id="tcounter">0</span>/1000 characters used into the freetext element, so no further instruction needed to form user.

After that you can always use <span style=...> directly in there to format the text that appears if desired.

So nice when something that's been bugging you works in the end...!
The administrator has disabled public write access.
The following user(s) said Thank You: dryfive, coach4, sharlene_c

Dynamically count/show/limit words in textarea 10 years 9 months ago #28205

Hi

I used your code and it seemed to work on a new form I created for testing but when I applied it to existing forms by editing, the fields still accept more than the limited number of characters. Does anyone have any idea why this would be so?

Thanks in advance for any help.
S
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!