Re: How to add a Validator for a TEXTBOX with TextMode = multiLine

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: i-Safire (zkvneml_at_hotmail.com)
Date: 05/25/04


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.



Relevant Pages

  • Re: Best way to access a textarea within a DIV
    ... |>>> to add the text but want to know best way to access the textarea. ... | Why would an input field be preferable to a textarea? ... A input/text control is for entering up to 255 characters of data. ...
    (comp.lang.javascript)
  • Re: Display multiple lines
    ... The data is collected in a ASP form "textarea" ... The data is then displayed in an HTML form. ... or line feed characters in the text, ... Data display process: ...
    (microsoft.public.inetserver.asp.general)
  • Re: Schema: error with restriction in simpleContent
    ... and want to restrict "foo" to the length of 10 characters, ... Well, restrict then extend. ... Element 'textarea': The attribute 'label' is required but ... sch1.xml fails to validate ...
    (comp.text.xml)
  • Re: How to upload form data containing special characters correctly?
    ... There is one textarea where users must put in text about their subject, so most of them cut 'n' paste it from Acrobat/Word/OpenOffce into their browser. ... And if they care cutting and pasting from a Word document or a PDF, chances are the document itself has the special characters. ... Nothing in PHP or MySQL would handle such characters; you'll have to handle them yourself, ...
    (comp.lang.php)
  • Re: Textarea code
    ... pass a reference to the textarea from the event handler using ... Again, pass a reference to the element using "this", and get maxLength ... The initial number is the number of remaining characters shown by my code is ... Incidentally, maxlength is not a valid attribute for textarea elements, ...
    (comp.lang.javascript)