We won again!

Great victory for the People - Tax Cut!

Properly Validate TextArea Length (IE vs. 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 database.

It appears that IE counts all characters in a string, and Firefox ignores newline characters.  That explains the difference in the result.  Now, how do we fix that?

My only solution at this point is to add a server-side validation in addition to JavaScript to prevent ugly SQL errors on update.

(Visited 39 times, 1 visits today)

5 Comments

  1. Useful blog website, keep me personally through searching it, I am seriously interested to find out another recommendation of it.

  2. Пишу тут раз обратной связи не нашла. У меня иногда пишет ошибку вот тут http://www.domainwebcenter.com Ошибка 403 «Доступ запрещен»
    Что мне делать ? я иногда статьи у вас беру для своей газеты.

  3. Спасибо! Буду теперь заходить на этот блог каждый день!Интересные посты – это ваш стиль безусловно!

1 Trackback / Pingback

  1. URL

Your question, correction or clarification Ваш вопрос, поправка или уточнение