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 ();">