Posts Tagged ‘ JavaScript ’

Properly Validate TextArea Length (IE vs. Firefox)

2017/06/26
By
Modified: 2017/11/12
TextArea Length - Firefox

Let’s consider this example, where HTML page has a TEXTAREA and an INBOX.  When user types inside TextArea, Inbox should show the length of TextArea string. <script type="text/javascript"> function TTLength(objTT){ var tt= document.getElementById('TXT1'); tt.value = objTT.value.length; } </script> <textarea onKeyDown="TTLength(this);" onKeyUp="TTLength(this);" rows="10"> This Text Area Contains a string With Newline Characters </textarea>  <input type="text" id="TXT1" value="TT Length"/> Let’s see how this page behaves in IE8 and in Firefox 3.6.11. IE8 Firefox As you can see that IE and FF return two different values for the length of an identical  string in TextArea and that could be a serious problem, if you are trying to validate the string length before updating the…

Read more »


Grow TextArea Height Along with User Input

2017/06/14
By
Modified: 2017/04/30
TextArea---Allow-to-Grow

There are situations, when you do not want to have scroll bars inside a TextArea. Main reason not to have scroll bars inside TextArea is to make your pages more mobile-friendly.  For example on iPhone Safari scroll bar inside TextArea will not even show up.  Another reason not to have scroll bars is to improve page readability.   When you have lots of TextArea(s) on a page,  it is much faster to review the information without scrolling inside each individual TextArea. Here is a solution that would allow you to set TextArea height exactly to the amount of information in it and grow its height as needed with user input. Your can use…

Read more »

ASP.NET Combine Validators and Client OnClick Events

2017/05/03
By
Modified: 2017/04/30

  Imagine you need to use control validators, and you also need to attach  additional logic to OnClick event. These two will fight with each other, if you use conventional interface features. If you add OnClick attribute too early (say in GridView_RowEditing event)  it will be overwritten by Validators.  If you add OnClick  attribute very late (say in  Render event) Validators logic will be lost. To make this work, you need to  use a special JavaScript function that combines both procedures. Here is how you do it: You need to change  a few things on the button that causes validation:                     <asp:ImageButton ID="imgUpdate" runat="server" CausesValidation="false"                         OnClientClick="return isValid(this);" ImageUrl="~/Images/Update32x32.png"                         Text="Update"…

Read more »