How to Submit a Form Using JavaScript
2010-03-17 17:24
525 查看
How to Submit a Form Using JavaScript
http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtmlGenerally, a form is submitted when the user presses a submit button. However, sometimes, you may need to submit the form programmatically using JavaScript.
JavaScript provides the form object that contains the submit() method. Use the 'id' of the form to get the form object.
For example, if the name of your form is 'myform', the JavaScript code for the submit call is:
document.forms["myform"].submit();
But, how to identify a form? Give an id attribute in the form tag
<form id='myform' action='formmail.pl'>
Here is the code to submit a form when a hyperlink is clicked:
<form name="myform" action="handle-data.php"> Search: <input type='text' name='query' /> <a href="javascript: submitform()">Search</a> </form> <script type="text/javascript"> function submitform() { document.myform.submit(); } </script>
Click the link below to see the code in action:
JavaScript Form Submit Example 1
相关文章推荐
- How to Submit a Form Using JavaScript
- How to Submit a Form Using JavaScript
- How To Submit Form Data by Using XMLHTTP or ServerXMLHTTP Object
- How to get blob data using javascript XmlHttpRequest by sync
- 简述JavaScript提交表单的方式 (Using JavaScript Submit Form)
- How to Detect Font-Smoothing Using JavaScript
- How to load a local .CSS file & JavaScript resources using iPhone UIWebView Class
- How to POST Form Data Using Ruby(转)
- JavaScript 提交表单的方式 (Using JavaScript Submit Form)
- How to simulate a Form POST request by using WinInet
- How to Submit a Form with Control + Enter
- How to submit data in InfoPath form services
- [转贴]How to work with stored procedures by using script in an Office InfoPath 2003 form
- JS: How to detect my browser version and operating system using JavaScript?
- How to invoke a JSF managed bean on a HTML DOM event using native JavaScript?
- How to Integrate Excel in a Windows Form Application using the WebBrowser
- 简述JavaScript提交表单的方式 (Using JavaScript Submit Form)
- How to post a form using fetch in react native
- js 提交表单的方式 (Using JavaScript Submit Form)
- How to create jigsaw puzzle from an image using javascript(拼图引擎)