Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > max size javascript validation on multiline textbox behaves differently in IE and FF

Reply
Thread Tools

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

 
 
write2atif write2atif is offline
Junior Member
Join Date: Apr 2009
Posts: 2
 
      04-30-2009
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[i] == 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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
onclick behaves differently when defined via javascript yawnmoth Javascript 17 10-02-2008 04:25 PM
Javascript behaves differently when opened as file:// vs. from local web server Nick Javascript 3 10-26-2007 07:33 PM
Math.sqrt(NaN) behaves differently on windows and linux Geert Fannes Ruby 1 04-04-2005 12:49 PM
how to define a variable to hold a multiline text input in perl from html multiline textbox dale zhang Perl Misc 8 11-30-2004 06:53 AM
same web page behaves differently on servers Do ASP .Net 1 11-16-2003 08:11 AM



Advertisments