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



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 6 (SP1)
  • Microsoft Internet Explorer (Programming) 5.01

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 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 6 service pack 2 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
   ---------------------------------------------------------
   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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, see the following Microsoft Web site: For additional information about the support options available from Microsoft, visit the following Microsoft Web site:

Modification Type:MinorLast Reviewed:10/10/2005
Keywords:kbHotfixServer kbQFE kbQFE kbIE600sp2fix kbIE600preSP2fix kbfix kbbug KB817979 kbAudITPRO