limit on textarea [solved]

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
J_Iceman05
Forum Commoner
Posts: 72
Joined: Wed Aug 03, 2005 10:52 am
Location: Las Vegas, NV

limit on textarea [solved]

Post 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.
Last edited by J_Iceman05 on Wed Jan 25, 2006 10:35 pm, edited 1 time in total.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post 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!
User avatar
J_Iceman05
Forum Commoner
Posts: 72
Joined: Wed Aug 03, 2005 10:52 am
Location: Las Vegas, NV

Post by J_Iceman05 »

That works perfect. Just what I was looking for.
Thank you very much.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

:D No problem, Happy you got it working.
Post Reply