I need to limit the chars typed in a textarea to 160 (size of an SMS :p) It works fine - as long as no one is copy-pasting text to it. Then my lil JS fails boohoo. So, could anyone help me out? Should I nail this to some other event than OnKeyPress or what?
Thanks in advance
[vbs]
function LimitText(fieldObj,maxChars)
{
var result = true;
if (fieldObj.value.length > maxChars)
{
result = false;
}
if (window.event)
{
window.event.returnValue = result;
}
That would be quite easy if it was a text input box instead of a textarea, but I guess the problem with that would be that 160 chars is a lot longer than most input boxes, and so the user wouldn’t easily be able to check over their sms entirely before posting…
Originally posted by Markdidj What happens to javascript form validation when javascript is turned off?
It doesn’t work. Thats why its only safe to use if you know how your user will be accessing your site, like a corporate intranet or something. Otherwise, validation should be done server side.