This topic is locked

Limit Number Of Characters In Text Area

3/6/2013 2:15:41 PM
PHPRunner General questions
H
herb200mph author

We have the code (below) that counts and limits characters in the text area input box.
However, the user can enter more than the limited characters while entering data.
After saving, the text entered is truncated to the set value of the limitation.
How can the code be modified to stop user input beyond the specified limit?
= = = = =
var ctrl3a = Runner.getControl(pageid, '3a');

document.getElementById('counter1').value = ctrl3a.getValue().length;
number_of_characters = 500;
function func1()

{

document.getElementById('counter1').value = ctrl3a.getValue().length;
if (ctrl3a.getValue().length>number_of_characters)

{

ctrl3a.setValue(ctrl3a.getValue().substr(0,number_of_characters));

document.getElementById('counter1').value = number_of_characters;

}

}

ctrl3a.on('keyup', func1);

Sergey Kornilov admin 3/6/2013

No, there is no easy way to do that.
Besides that, it sounds like a bad idea. What if your user pasted a larger amount of text into that field and edits it to make it fit? The code you propose adding will prevent her from doing so.

H
herb200mph author 3/6/2013



No, there is no easy way to do that.
Besides that, it sounds like a bad idea. What if your user pasted a larger amount of text into that field and edits it to make it fit? The code you propose adding will prevent her from doing so.


Sergey:
Jane gave us this code.
At present, a user can add text over the amount, but when it saves, it truncates it anyway.
Its OK if they cannot edit if a large amount of text is pasted.
We can caution them about that.
Client wants a key-in fixed limit, no matter how it gets entered.
Thanks.