Click to See Complete Forum and Search --> : setting maximum characters in a div


marko_one
10-20-2003, 09:06 AM
Hi All,
I have a contenteditable div which I am using for a rich text box, I pre-fill it with

document.all.myTextDiv.innerHTML = "<%=myText.value%>"

what I need to do is check limit the maximum amout of characters typed into the editable region. I was thinking of using something like :

function setMax(myDivText, maxlength)
{
if (myDivText.value.length > maxlength)
{
myDivText.value = myDivText.value.substring(0,maxlength);
}
}

to set this maximum length, but it doesnt seem to work, can anybody put me straigh on this one?

thanks

marko.

Khalid Ali
10-20-2003, 09:27 AM
Looks like it should work,only problem I can think of is if you call this method apropriately,
this method should be called in every key up event in that div.

fredmv
10-20-2003, 09:34 AM
Check the text element from the form's value first, then output that. In other words, do exactly what you're doing here, but on the text or textarea element from the previous page.