• 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: best way to limit text in textarea?

best way to limit text in textarea? 17 years 2 months ago #1855

  • bob1138
  • bob1138's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
Is there a way to use javascript or something within rsform! to limit the amount of characters in a textarea? I want to set a max of 100 characters
The administrator has disabled public write access.

Re:best way to limit text in textarea? 17 years 15 hours ago #2906

  • hearts
  • hearts's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 13
Ditto - same question only with limiting the number of words vs. characters in a textarea?
The administrator has disabled public write access.

Re:best way to limit text in textarea? 17 years 12 hours ago #2908

I have the same need. I have found some Javascript that will do it:
javascript.internet.com/forms/limit-textarea.html

I added the javascript to a .js file, uploaded to my server and added this to the Script called on form display. This will load the .js file into the HTML header
$doc = &JFactory::getDocument();
$doc->addScript('/limit.js');

The problem is that rsform adds brackets around the form field name attribute, which throws off the javascript. So <textarea name=\"form[Field]\" will not work because of the brackets, yet this is what RSForm creates.

So this would all work if I could find a way to not use brackets in the name=\"\" attribute.

Is it possible to not use brackets in the name attribute?
The administrator has disabled public write access.

Re:best way to limit text in textarea? 17 years 11 hours ago #2909

From looking at the code, my guess is the developers are using the brackets to automaicaly put the data into arrays when it is processed... so I wonder if there is a way to tweak the JS to ignore/replace the brackets...
The administrator has disabled public write access.

Re:best way to limit text in textarea? 17 years 10 hours ago #2911

I got it working. I meant to post a reply to this topic but ended up creating a whole new topic! Sorry:
www.rsjoomla.com/index.php/RSform-How-To...-figured-it-out.html
The administrator has disabled public write access.

Re:best way to limit text in textarea? 17 years 10 hours ago #2912

Ok, I got it working!
First, I used a different snippet of javascript, just because I liked this one better:
www.mediacollege.com/internet/javascript...imit-characters.html

#1) So copy this code into a file called limit.js
Code:



function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
limitCount.value = limitNum - limitField.value.length;
}
}




Save the limit.js file somewhere on your server.

#2) Create your form and the text area field you want

#3) While editing the text area field, add this code to the Additional Attributes field:
Code:


onKeyDown=\"limitText(this.form'],this.form.countdown,1500);\" onKeyUp=\"limitText(this.form'],this.form.countdown,1500);\"



In this case, replace Fieldname with the name of your field.

#4) In the field style, add this somewhere below the {field}:
Code:


<br />
<font size=\"1\">(Maximum characters: 1500)<br>
You have <input readonly type=\"text\" name=\"countdown\" size=\"3\" value=\"1500\"> characters left.</font>



#5) Save your field and add this code to the scripts tab for your form under \"Script called on form display\" --
Code:


$doc = &JFactory::getDocument();
$doc->addScript('/path-to-your-script-/limit.js');



#6) Save the form and that's it!

When a user types, they will be limited to 1500 characters and the form will tell them how many characters they have left.
The administrator has disabled public write access.

Re:best way to limit text in textarea? 16 years 11 months ago #2927

  • hearts
  • hearts's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 13
Thanks for the help. Questions: 1. Can this be done for words instead of characters? 2. What is JFactory? I get an error that JFactory cannot be found. Thanks!
The administrator has disabled public write access.

Re:best way to limit text in textarea? 16 years 7 months ago #4618

  • Geday
  • Geday's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Hi Hearts,

Any luck in finding a way to limit the words instead of characters?

Thanks.
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!