Monday, September 15, 2008

Textarea maxlength check - Javascript

/* Function to allow keypress until maximum length reach */
function validate(textarea, maxlength){

if (maxlength <= 0 || maxlength == undefined)
length = 10; /* default length */

if (textarea.length >= maxlength)
return false;
else
return true;
}

.....
.....
< textarea name="message" onkeypress="return validate(this.value, 10);">< /textarea>

No comments:

Popular Posts