max size javascript validation on multiline textbox behaves differently in IE and FF

Discussion in 'Software' started by write2atif, Apr 30, 2009.

  1. write2atif

    write2atif

    Joined:
    Apr 30, 2009
    Messages:
    1
    hi everyone

    i have an asp.net page, in which i write javascript block to set the maximum size property of multiline textbox. it behaves differently in FF and IE. I will describe scenerio . i set the max size of 10 for eample in IE when i write press two keys say aa and press enter and then on next line again write aa and press enter and on next line again write aa and now if i will try to write any thing then i cant able to write any thing. so there will be 6 time 'a' will appear on three lines because i press enter two times which take two characters for carriage return and line feed. So this is fine in IE but when itest the same scenario in FF then i think that FF takes only one character for Enter Key (mean for carriage return and line feed) so i can write more characters in FF. I think it works abnormally in FF. My page code is given below. i want same functionality in FF as in IE. thanx in advance


    <head id="h1" runat="server">

    <title>Untitled Page</title>



    </head>

    <script language="javascript" type="text/javascript">

    var _lastValue="";


    function GetTextArea()
    {

    return document.getElementById('<%=txtSalutation.ClientID%>');
    }





    function TextareaKeyPress(event)
    {

    //get pointer to text control:

    var objTextArea=GetTextArea();


    //get value:

    var strValue=objTextArea.value;


    //get max chars:

    var maxChars=10;


    //check if exceeded:

    if (strValue.length >= maxChars)
    {

    //check if key pressed was arrow, backspace or such:

    if ((!event)||(!event.keyCode))return false;


    var arrAllowedChars=new Array(8, 9, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46);

    return InArray(arrAllowedChars, event.keyCode);
    }

    return true;
    }



    function TextareaKeyUp(event)
    {

    //get pointer to text control:

    var objTextArea=GetTextArea();


    //get value:

    var strValue=objTextArea.value;


    //get max chars:

    var maxChars=10;


    //check if exceeded:

    if (strValue.length >= maxChars)
    {

    if (_lastValue.length != strValue.length)
    {

    //crop to maximum size:

    objTextArea.value = strValue.substr(0, maxChars);

    }

    strValue=objTextArea.value;

    }



    //store last value:

    _lastValue = strValue;

    }



    function TextareaPaste(event)
    {

    //initiate keypress and keyup events:

    var s1=setTimeout("TextareaKeyPress();", 100);var s2=setTimeout("TextareaKeyUp();", 500);
    }



    function InArray(arr, key)
    {

    for (var i=0; i<arr.length; i++)
    {

    if (arr == key)return true;
    }

    return false;
    }

    </script>

    <body>

    <form id="form1" runat="server">

    <asp:TextBox TextMode="MultiLine" Rows="3" ID="txtSalutation" runat="server" onkeypress="javascript:TextareaKeyPress(event);" onkeyup="javascript:TextareaKeyUp(event);" onbeforepaste="javascript:TextareaPaste(event);"></asp:TextBox>

    </form>
    </body>

    </html>
     
    write2atif, Apr 30, 2009
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jimmy
    Replies:
    3
    Views:
    1,742
    Render Me
    Sep 12, 2005
  2. Vayalumkal
    Replies:
    1
    Views:
    19,189
    enirosh
    Oct 14, 2008
  3. har29oct
    Replies:
    0
    Views:
    1,424
    har29oct
    Mar 28, 2009
  4. kasbekar.ajay

    Asp.Net Bind javascript to textbox

    kasbekar.ajay, Apr 22, 2010, in forum: Software
    Replies:
    0
    Views:
    3,087
    kasbekar.ajay
    Apr 22, 2010
  5. jamilnasir

    unable to access textbox in javascript

    jamilnasir, May 17, 2010, in forum: Software
    Replies:
    1
    Views:
    1,194
    FS2009
    May 21, 2010
Loading...

Share This Page