Page 1 of 1

limit on textarea [solved]

Posted: Wed Jan 25, 2006 9:59 pm
by J_Iceman05
I tried searching for this, but I found nothing that was actually relevant... I wasn't even sure what to search for... so here it goes...

the html tag <textarea> doesn't have a 'maxlength' feature that restricts the number of characters the user can input like the <input> tag does... (unless I am missing something)

So I am sure I need javascript to do this.
so far I have this...

(I want to only allow upto 150 characters in the textarea)

Code: Select all

function bioMax() {
    var textareaLen = '';
    if (document.forms['addMember'].elements['add_bio'].value.length > 150) {
        textareaLen = document.forms['addMember'].elements['add_bio'].value;
    }
}
currently... this does nothing. I am sure I need to select anything over 150 and delete it.. or select everything upto the 150 character and set that as the textarea's value or something like that... but I dont know how to do this
Or is there a way to just not allow any more characters?

I don't want to disable it or anything like that because I still want them to be able to edit it or delete or whatever they need to do... just not allow more than 150 characters in the area.

Thanks in advance for your help.

Posted: Wed Jan 25, 2006 10:05 pm
by nickman013
This is a very good tutorial on that javascript.

:arrow: http://www.mediacollege.com/internet/ja ... cters.html

Good Luck, if you need help with it, if it doesnt work, just ask!

Posted: Wed Jan 25, 2006 10:35 pm
by J_Iceman05
That works perfect. Just what I was looking for.
Thank you very much.

Posted: Wed Jan 25, 2006 10:38 pm
by nickman013
:D No problem, Happy you got it working.