Re: How to add a Validator for a TEXTBOX with TextMode = multiLine
From: i-Safire (zkvneml_at_hotmail.com)
Date: 05/25/04
- Next message: Tammy: "Re: need help with making site dynamic....."
- Previous message: Steve Hoyer: "Re: File not Found error on asp page"
- In reply to: RSB: "How to add a Validator for a TEXTBOX with TextMode = multiLine"
- Messages sorted by: [ date ] [ thread ]
Date: 25 May 2004 09:02:30 -0700
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_MaxLen(prm_oTextarea_Obj)
{ var var_sKey_Code, var_aKey_Special, var_bResult,
var_oTextarea_TxtRng;
var_oTextarea_TxtRng = prm_oTextarea_Obj.createTextRange();
var_aKey_Special = [8,17,18,27,33,34,35,36,37,38,39,40,45,46,114];
var_bResult = true;
var_sKey_Code = event.keyCode;
if (var_sKey_Code == 86)
{ if (event.ctrlKey) var_bResult =
fun_mTextarea_Paste(prm_oTextarea_Obj); }
if(prm_oTextarea_Obj.value.length >= prm_oTextarea_Obj.maxLen)
{ var_bResult = false;
if (var_oTextarea_TxtRng.queryCommandState('OverWrite') &&
(prm_oTextarea_Obj.value.length == prm_oTextarea_Obj.maxLen))
{ var_bResult = true; }
else
{
for (i=0; i<var_aKey_Special.length; i++)
{ if (var_sKey_Code == var_aKey_Special[i]) {var_bResult = true;
break;} }
}
}
return var_bResult;
}
function fun_mTextarea_Paste(prm_oTextarea_Obj)
{ var var_sClipboard_Text;
var_sClipboard_Text = window.clipboardData.getData("Text");
prm_oTextarea_Obj.TxtRng =
document.selection.createRange().duplicate();
if (prm_oTextarea_Obj.TxtRng && prm_oTextarea_Obj.createTextRange)
{ prm_oTextarea_Obj.TxtRng.text =
prm_oTextarea_Obj.TxtRng.text.charAt(prm_oTextarea_Obj.TxtRng.text.length
- 1) == ' ' ? var_sClipboard_Text + ' ' : var_sClipboard_Text;
}
else
{ prm_oTextarea_Obj.TxtRng.text = var_sClipboard_Text;}
prm_oTextarea_Obj.value = prm_oTextarea_Obj.value.substring(0,
prm_oTextarea_Obj.maxLen);
return false;
}
</SCRIPT>
</HEAD>
<BODY>
<textarea maxLen=10 onkeydown="return
fun_pTextarea_MaxLen(this);"></textarea>
</BODY>
</HTML>
(ref:phoenix398017)
"RSB" <rsbamra@hotmail.com> wrote in message news:<T2Ooc.1416$8h3.123@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.
- Next message: Tammy: "Re: need help with making site dynamic....."
- Previous message: Steve Hoyer: "Re: File not Found error on asp page"
- In reply to: RSB: "How to add a Validator for a TEXTBOX with TextMode = multiLine"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|