try this the following, this will prevent user from entering more
characters than maxLen specified; it works in all the situations,
including:
1) copy and paste;
2) insert key on;
<HTML>
<HEAD>
<SCRIPT>
function fun_pTextarea_M axLen(prm_oText area_Obj)
{ var var_sKey_Code, var_aKey_Specia l, var_bResult,
var_oTextarea_T xtRng;
var_oTextarea_T xtRng = prm_oTextarea_O bj.createTextRa nge();
var_aKey_Specia l = [8,17,18,27,33,3 4,35,36,37,38,3 9,40,45,46,114];
var_bResult = true;
var_sKey_Code = event.keyCode;
if (var_sKey_Code == 86)
{ if (event.ctrlKey) var_bResult =
fun_mTextarea_P aste(prm_oTexta rea_Obj); }
if(prm_oTextare a_Obj.value.len gth >= prm_oTextarea_O bj.maxLen)
{ var_bResult = false;
if (var_oTextarea_ TxtRng.queryCom mandState('Over Write') &&
(prm_oTextarea_ Obj.value.lengt h == prm_oTextarea_O bj.maxLen))
{ var_bResult = true; }
else
{
for (i=0; i<var_aKey_Spec ial.length; i++)
{ if (var_sKey_Code == var_aKey_Specia l[i]) {var_bResult = true;
break;} }
}
}
return var_bResult;
}
function fun_mTextarea_P aste(prm_oTexta rea_Obj)
{ var var_sClipboard_ Text;
var_sClipboard_ Text = window.clipboar dData.getData(" Text");
prm_oTextarea_O bj.TxtRng =
document.select ion.createRange ().duplicate();
if (prm_oTextarea_ Obj.TxtRng && prm_oTextarea_O bj.createTextRa nge)
{ prm_oTextarea_O bj.TxtRng.text =
prm_oTextarea_O bj.TxtRng.text. charAt(prm_oTex tarea_Obj.TxtRn g.text.length
- 1) == ' ' ? var_sClipboard_ Text + ' ' : var_sClipboard_ Text;
}
else
{ prm_oTextarea_O bj.TxtRng.text = var_sClipboard_ Text;}
prm_oTextarea_O bj.value = prm_oTextarea_O bj.value.substr ing(0,
prm_oTextarea_O bj.maxLen);
return false;
}
</SCRIPT>
</HEAD>
<BODY>
<textarea maxLen=10 onkeydown="retu rn
fun_pTextarea_M axLen(this);"></textarea>
</BODY>
</HTML>
(ref:phoenix398 017)
"RSB" <rs*****@hotmai l.com> wrote in message news:<T2******* *********@news. cpqcorp.net>...
Hi Guys..
its me again.. ;o))
now i have a TextBox with properties Textmode = singleline and MaxLength =
100. So this works fine and i cannot enter more then 100 Chars. But as soon
as i change the TextMode to MultiLIne the MaxLength gets ignore as it is
painted as TEXTAREA. so how do i add a validator control to make sure that
user is not entering more than 100 Characters..
Thank you for the help in advance.
RSB.