Submit a form Via Enter : Form Submit « Form Control « JavaScript DHTML

Home
JavaScript DHTML
1.Ajax Layer
2.Data Type
3.Date Time
4.Development
5.Document
6.Dojo toolkit
7.Event
8.Event onMethod
9.Ext JS
10.Form Control
11.GUI Components
12.HTML
13.Javascript Collections
14.Javascript Objects
15.Javascript Properties
16.jQuery
17.Language Basics
18.Mochkit
19.Mootools
20.Node Operation
21.Object Oriented
22.Page Components
23.Rico
24.Scriptaculous
25.Security
26.SmartClient
27.Style Layout
28.Table
29.Utilities
30.Window Browser
31.YUI Library
JavaScript DHTML » Form Control » Form Submit 




Submit a form Via Enter
   
<!-- 
     Example File From "JavaScript and DHTML Cookbook"
     Published by O'Reilly & Associates
     Copyright 2003 Danny Goodman
-->

function submitViaEnter(evt) {
    evt = (evt? evt : event;
    var target = (evt.target? evt.target : evt.srcElement;
    var form = target.form;
    var charCode = (evt.charCode? evt.charCode :
        ((evt.which? evt.which : evt.keyCode);
    if (charCode == 13) {
        if (validateForm(form)) {
            form.submit();
            return false;
        }
    }
    return true;
}

<input type="text" ... onkeypress="return submitViaEnter(event)">

----------

<form action="..." method="GET" name="sampleForm" onsubmit="return false">
First Name: <input type="text" size="30" name="name1" id="name1"
    onkeypress="return focusNext(this.form, 'name2', event)"
    onchange="isNotEmpty(this)" /><br>
Last Name: <input type="text" size="30" name="name2" id="name2"
    onkeypress="return focusNext(this.form, 'eMail', event)"
    onchange="isNotEmpty(this)" /><br>
Email Address: <input type="text" size="30" name="eMail" id="eMail"
    onkeypress="return submitViaEnter(event)" /><br>
<input type="reset" /> <input type="button" value="Submit"
    onclick="if (validateForm(this.form)) {this.form.submit( )}" />
</form>
           
         
    
    
  














Related examples in the same category
1.Form Submit action
2.Return the method used when sending form data
3.Convert a passed form reference to a string formatted like a JavaScript array of objects
4.Use form select control to trigger the action
5.form on submit event
6.Last-Minute Checking Before Form Submission
7.Use Image to trigger submit and reset actions
8.Submit a form by sending out an email
9.Adjusting a Server Submission Action
10.Demo: Ajax form submit
11.html input mask
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.