Press enter to submit events, and block press enter to submit events.

Source: Internet
Author: User

 
Prevents carriage return from submitting
 
<Form runat = "server" id = "form1" onkeypress = "javascript: Return saaskeydown (event)">
 
Press enter to submit
<SCRIPT> function getkeycode (EVT) {If (typeof (EVT) = 'string') return EVT. charcodeat (0); Return document. All? Event. keycode: (EVT & EVT. Which )? EVT. which: 0;} function saaskeydown (event) {If (getkeycode (event) = 13) {return false ;}} function searchenter (event) {If (getkeycode (Event) ==13) {newssearch () ;}} function newssearch () {var key = document. getelementbyid ("newssearchkey "). value; If (Key = "Enter keywords") {alert ("Enter keywords");} else {window. location. href = "http://search.soufun.com/search? Dir = News & Q = "+ escape (key );}} </SCRIPT> <input type = "hidden" name = "dir" value = "news"> <Div class = "Left Kuang"> <input name = "Q" size = "20" type = "text" class = "Kuang" id = "newssearchkey" value = "input keyword" onfocus = "If (this. value = 'input keyword ') This. value = '';" onblur = "If (this. value = '') This. value = 'enter keyword '; "onkeydown =" searchenter (event ); "/> </div> <Div class =" Left "> <input type =" button "value =" "class =" subbut "onclick =" newssearch () "/> </div>

 

So I have summarized that there are two ways to submit a form using JavaScript (based on my current understanding)

1. Document. formname. Submit ();

2. var form = Document. getelementbyid (ID );
Form. Submit ();

Http://blog.csdn.net/tohmin/archive/2008/08/01/2752556.aspx
 
How to resolve the onsubmit event not triggered when the button calls the form. Submit () method)
<Input type = "button" value = "test"Onclick = "If (document. myform. onsubmit ()! = False) document. myform. Submit ();">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.