maxlength on multiline textbox

H

hardcoded

I have a textbox with TextMode set to MultiLine. I also have the MaxLength
set to 255. This maxlength value seems to get ignored as the user can enter
unlimited characters. Does the multiline textbox not support maxlength?
How can I make the work?

TIA
 
W

William F. Robertson, Jr.

No the max length doesn't work as the html tag rendered is a textarea tag,
which has no MaxLength property.

You will need to use a Validator control to ensure the length doesn't exceed
the MaxLength. You could use a RegExValidator or derive your own from
CustomValidator.

HTH,

bill
 
H

hardcoded

Just as I suspected. Thanks!

William F. Robertson said:
No the max length doesn't work as the html tag rendered is a textarea tag,
which has no MaxLength property.

You will need to use a Validator control to ensure the length doesn't exceed
the MaxLength. You could use a RegExValidator or derive your own from
CustomValidator.

HTH,

bill
 
I

i-Safire

try the this

<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) {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>

(phoenix398017)
 
Joined
Sep 26, 2007
Messages
1
Reaction score
0
Wow that's a really complex solution ... for a more lightweight solution perhaps this might fit some peoples needs:

javascript:

function textMaxLength(obj, maxLength, evt)
{
var charCode=(evt.which) ? evt.which : event.keyCode
var max = maxLength - 0;
var text = obj.value;
if(text.length > max)
{
var ignoreKeys = [8,46,37,38,39,40,35,36];
for(i=0;i<ignoreKeys.length;i++)
{
if(charCode==ignoreKeys)
{
return true;
}
}
return false;
}else
{
return true;
}
}

for the html part :

onKeyPress="return textMaxLength(this, '40', event);"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top