Page 1 of 1

Limit number of characters in textfields

Posted: 2014-03-10 14:30
by JEngels
Hi,
I want to limit the number of characters the user can enter in the textarea.
An alternative solution would be a character-counter below the textfield.
Any ideas to realize that?

Thanks.
Koepi

Re: Limit number of characters in textfields

Posted: 2014-03-24 14:31
by a.gneady
You can use javascript to achieve this ... create a file in the "hooks" folder, naming it "tablename-dv.js" (where tablename is the name of the concerned table) and add code similar to this in it:

Code: Select all

jQuery(function(){
   jQuery('#fieldname').attr('maxlength', 40);
});
(where fieldname is the name of the concerned field). Change 40 to the desired limit.

Re: Limit number of characters in textfields

Posted: 2014-03-28 12:37
by JEngels
Thanks Ahmad, that works fine!
But realize that "maxlenght" doesn't work in IE9/8.
Spent a lot of time to find that out.
Installed IE11 - thats okay (FF also).

My next try: install a character counter below the textfield I want to be limited/counted.
Is this also possible by using the hook folder, or only by adding code directly in the table.php?

Re: Limit number of characters in textfields

Posted: 2014-03-28 20:30
by a.gneady
No it can be added using the same hook file using javascript ... you can find through Google lots of examples on how to implement this ... for example: http://stackoverflow.com/questions/5371 ... n-textarea