Microsoft Knowledge Base Email Alertz

(828907) - Explains that pressing ENTER after you input information in a form will submit the form instead of moving the focus to the next field. To work around this behavior, you can convert the ENTER keystroke to a TAB keystroke. Includes sample DHTML code.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 828907 - Last Review: May 30, 2007 - Revision: 3.2

The form is submitted when you press ENTER on a Form page in SharePoint Designer 2007 or in FrontPage 2003

For a Microsoft FrontPage 2002 version of this article, see 302905  (http://kbalertz.com/Feedback.aspx?kbNumber=302905/ ) .
For a Microsoft FrontPage 2000 version of this article, see 292760  (http://kbalertz.com/Feedback.aspx?kbNumber=292760/ ) .

On This Page

SYMPTOMS

You type information in a form on a Web page, and then you press ENTER on the keyboard. When you do this, the form is submitted instead of the insertion point moving to the next form field.

CAUSE

This behavior occurs because the default behavior for a Web browser is to submit the form when you press ENTER.

WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. Note You may receive an error message if you copy the examples directly from this article and paste them into FrontPage. The angle brackets (<and>) may appear as escaped HTML code (<and>). To work around this behavior, paste the script into a blank Notepad document, and then copy it from Notepad before you paste it into FrontPage.
To work around this behavior, use Dynamic HTML (DHTML) to intercept the ENTER keystroke and convert it to a TAB keystroke. To do this, follow these steps, as appropriate for the product that you are using.

Microsoft Office SharePoint Designer 2007

Important The following sample code uses custom DHTML that may not be available in all browsers.
  1. Open a Web in SharePoint Designer 2007, and then create a new page.
  2. Insert a form on the page. To do this, follow these steps:
    1. In the Toolbox pane, right-click Form underForm Controls, and then click Insert.
    2. Right-click the form, and then click Form Properties.
    3. In the Form Name box, type myForm.
    4. Click OK.
  3. Add two Text Area boxes to the form. To do this, follow these steps:
    1. In the Toolbox pane, right-click Text Area underForm Controls, and then click Insert.
    2. Position the insertion point to the right of the Text Area box, and then press ENTER.
    3. In the Toolbox pane, right-click Text Area underForm Controls, and then click Insert.
    You should now have two Text Area boxes, one under the other.
  4. Delete the Submit button and the Reset button.
  5. Switch to Code view, and then make the following changes:
    1. Locate the <body> tag, and then change it to the following tag:
       <body onContextMenu="return false" onKeyDown="if (window.event.keyCode==13) window.event.keyCode=9;">
      						
      
    2. Locate the </form> tag, and then change it to the following tag:
      <!-- show a SUBMIT button -->
      <input onKeyDown="if (window.event.keyCode==13) myForm.submit();" type="submit" value="Submit"/><br>
      
      <!-- show a RESET button -->
      <input onKeyDown="if (window.event.keyCode==13) resetForm();" onClick="resetForm();" type="button" value="Reset"/><br>
      
      <!-- DHTML script to reset the form -->
      <script language="JavaScript">
      <!--
      // Set the focus of the form to the first element.
      myForm.elements(1).focus();
      function resetForm()
      {
      // Prompt to reset the form.
      if (confirm('Are you sure you want to clear the form?'))
      window.location.reload(); // Reload the page to clear the form.
      }
      //-->
      </script>
      
      </form>
      
      
  6. Save the page as Formtest.htm in your Web.
When you view this page in Microsoft Internet Explorer and then press ENTER, the page is captured and converted to a TAB keystroke. This occurs unless you press the ENTER key when either the Submit button or the Reset button has focus.

Microsoft Office FrontPage 2003

Important The following sample code uses custom DHTML that may not be available in all browsers.
  1. Open a Web in FrontPage 2003, and then create a new page.
  2. Insert a form on the page. To do this, follow these steps:
    1. On the Insert menu, point to Form, and then click Form.
    2. Right-click the form, and then click Form Properties.
    3. In the Form Name box, type myForm.
    4. Click OK.
  3. Add two text boxes to the form. To do this, follow these steps:
    1. On the Insert menu, point to Form, and then click Textbox.
    2. Press ENTER.
    3. On the Insert menu, point to Form, and then click Textbox.
  4. Delete the Submit button and the Reset button.
  5. Switch to Code view, and then make the following changes:
    1. Locate the <body> tag, and then change it to the following tag:
       <body onContextMenu="return false" onKeyDown="if (window.event.keyCode==13) window.event.keyCode=9;">
      						
      
    2. Locate the </form> tag, and then change it to the following tag:
      <!-- show a SUBMIT button -->
      <input onKeyDown="if (window.event.keyCode==13) myForm.submit();" type="submit" value="Submit"><br>
      
      <!-- show a RESET button -->
      <input onKeyDown="if (window.event.keyCode==13) resetForm();" onClick="resetForm();" type="button" value="Reset"><br>
      
      <!-- DHTML script to reset the form -->
      <script language="JavaScript">
      <!--
      // Set the focus of the form to the first element.
      myForm.elements(1).focus();
      function resetForm()
      {
      // Prompt to reset the form.
      if (confirm('Are you sure you want to clear the form?'))
      window.location.reload(); // Reload the page to clear the form.
      }
      //-->
      </script>
      
      </form>
      
      
  6. Save the page as Formtest.htm in your Web.
When you view this page in Microsoft Internet Explorer and then press ENTER, the page is captured and converted to a TAB keystroke. This occurs unless you press the ENTER key when either the Submit button or the Reset button has focus.

STATUS

This behavior is by design.

APPLIES TO
  • Microsoft Office SharePoint Designer 2007
  • Microsoft Office FrontPage 2003
Keywords: 
kbforms kbprogramming kbinfo KB828907
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate