Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

BUG: Static HTML becomes editable in Internet Explorer


View products that this article applies to.

Symptoms

When a user enters data in a TextBox control, and then clicks the next TextBox control to enter data there, the insertion point disappears. If the user starts to type, the keystrokes appear inside the static text under the location on the page where the user clicked. When a user traps the onchange event for the first TextBox control to run code, more text or other Web page elements appear between the two TextBox controls. Also, the second TextBox control moves away from the insertion point position.

↑ Back to the top


Workaround

To work around this problem, do any one of the following:
  • Use the onblur event instead of the onchange event to run the validation code.
  • Change the placement of the page elements to prevent element movement.
  • Use the window.setTimeout function to reposition the insertion point, as in the following sample code.
    <table id="tableWithProblem">
      <tr>
        <td>
          <input id="tb1" type="text" onchange="validate()" value="">
          <span class="hiddenText" id="msg">
            The value contains text!
          </span>
        </td>
        <td>
          <!-- Added code to the ONFOCUS event of the affected text box -->
          <input id="tb2" type="text" value="" onfocus='window.setTimeout("tb2.select();",10);'>
          <!--<input id="tb2" type="text" value="">-->
        </td>
      </tr>
    </table>
    Alternatively, you can use the onmousedown event to fire only when the mouse is used to put focus in the TextBox control.

    In this sample code, notice that the .select method is used instead of the .focus method. Technically, the TextBox control already has focus. However, functionally, it does not. Therefore, the .select method is used to move the insertion point to the correct location.

    For more information about the window.setTimeout function, visit the following Microsoft Developer Network (MSDN) Web site:

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

↑ Back to the top


More information

Steps to reproduce the problem

  1. Save the following code as an HTML page.
    <HTML>
      <HEAD>
        <title>Dynamic Focus Problem</title>
        <style>
         SPAN.HiddenText { Display: none }
         SPAN.RedText { COLOR: red }
        </style>
        <script>
          function validate() {
             if (tb1.value.length > 0) {
               msg.className = "redText";
             }
             else {
               msg.className = "hidden";
             }
           }
        </script>
      </HEAD>
      <body>
        <table id="tableWithProblem">
          <tr>
            <td>
              <input id="tb1" type="text" onchange="validate()" value="">
              <span class="hiddenText" id="msg">The value contains text!</span>
            </td>
            <td>
               <input id="tb2" type="text" value="">
           	</td>
          </tr>
         </table>
      </body>
    </HTML>
  2. Open the page in Microsoft Internet Explorer.
  3. Click the TextBox control on the left, and then type some text in the TextBox control.
  4. Click the TextBox control on the right.

    Notice that The value contains text! appears between the TextBox controls. Also, notice that the second TextBox control has moved to the right, and the insertion point does not appear.
  5. Type some text.

    Notice that the text appears in the static page area.

↑ Back to the top


Properties

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

↑ Back to the top


Keywords: KB843164, kbbug

↑ Back to the top

Article Info
Article ID : 843164
Revision : 4
Created on : 5/18/2007
Published on : 5/18/2007
Exists online : False
Views : 341