OnChange Event Fires Unexpectedly When You Tab Out of a Text Area for the First Time

This article has been archived. It is offered "as is" and will no longer be updated.
Symptoms
When you press the TAB key in a TEXTAREA control on a Web page, the OnChange event fires even though the contents of the control have not changed. That is, Internet Explorer incorrectly detects that a change occurred in the TEXTAREA control, even though no change is made.
Cause
This problem occurs if you use script to set the text of the TEXTAREA control, and if either of the following conditions is true:
  • The text contains only a line feed(" chr(10)" or "\n") character.
  • The text contains a line feed(" chr(10)" or "\n") character and a carriage return("chr(13)" or "\r") character, in that specific order.
In this situation, Internet Explorer incorrectly processes the text of the TEXTAREA control. As a result, the OnChange event fires, even though the contents of the object have not changed.
Resolution

Internet Explorer 6.0 Service Pack 1



A supported hotfix is available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing this specific problem. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next software update that contains this hotfix.

If the hotfix is available for download, there is a "Hotfix download available" section at the top of this Knowledge Base article. If this section does not appear, contact Microsoft Customer Service and Support to obtain the hotfix.

Note If additional issues occur or if any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft Web site: Note The "Hotfix download available" form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language. The Global version of this fix has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
   Date         Time   Version         Size       File name   ---------------------------------------------------------   03-Apr-2003  17:44  6.0.2800.1184   2,787,840  Mshtml.dll

Internet Explorer 5.01 Service Pack 3



A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Internet Explorer 5.01 service pack 4 that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the fix. For a complete list of Microsoft Product Support Services phone numbers and information about support costs, visit the following Microsoft Web site: Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question. The global version of this fix has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
   Date         Time   Version         Size       File name   ---------------------------------------------------------   02-Apr-2003  23:53  5.0.3517.200    2,356,496  Mshtml.dll

Workaround
To work around this problem, do one of the following, as appropriate to your situation:
  • Use the carriage return character before the line feed character in the TEXTAREA control. The following code demonstrates a workaround for the example that was shown earlier in this article:
     <HTML><HEAD></HEAD>	<BODY >	<TEXTAREA id="TEXTAREA1" name="TEXTAREA1" OnChange="test()" style="width:400px;height:80px"></TEXTAREA><script language="JScript">var str="A" + "\r"+"\n" + "B";document.all("TEXTAREA1").value=str;function test(){alert("OnChange fired");}</script>	</BODY></HTML>
  • Set a global flag. For example:
    var flag = true;function test(){//Workaround	if(flag == true)	{		window.event.cancel = true;		flag = false;	}		else		alert('OnChange fired');}
Status
Microsoft has confirmed that this is a problem in Microsoft Internet Explorer.
More information

Steps to Reproduce the Problem

  1. Paste the following code in notepad, and then save it as TEXTAREA.htm.
    <HTML><HEAD></HEAD>	<BODY >	<TEXTAREA id="TEXTAREA1" name="TEXTAREA1" OnChange="test()" style="width:400px;height:80px"></TEXTAREA><script language="JScript">var str="A" + "\n" + "B";document.all("TEXTAREA1").value=str;function test(){alert("OnChange fired");}</script>	</BODY></HTML>
  2. Double-click TEXTAREA.htm to open it in Internet Explorer.
  3. Click inside the TEXTAREA control, and then press the TAB key. An "OnChange fired" message appears.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS
Properties

Article ID: 817979 - Last Review: 11/01/2013 21:26:00 - Revision: 2.0

  • Microsoft Internet Explorer 6.0
  • kbnosurvey kbarchive kbautohotfix kbhotfixserver kbqfe kbie600sp2fix kbie600presp2fix kbfix kbbug KB817979
Feedback