Brief Introduction to the JavaScript form submission method (UsingJavaScriptSubmitForm) _ javascript skills

Source: Internet
Author: User
This article briefly describes how to submit a form using JavaScript (UsingJavaScriptSubmitForm). If you want to submit a form using Javascript, refer to the question of submitting a form using JavaScript in a recent project, I have done it several times before, but it is not comprehensive enough. This time I have summarized several methods for submitting forms using JavaScript, compared them, and selected a method that is best suited to this project.

I am currently working on a small User Creation System for Sun Communication Suite. We all know that we can access the server through forms, Ajax and links. The simplest way is to use connections, for example: first Page, write all the required data to the hyperlink. If you can observe it, you will know that in the above link, only currentPage is changed, and other parameters such as event, keyword, searbyBy and cn are unchanged, so I thought that if I can encapsulate these unchanged parameters in a form, when a user clicks the hyperlink above, I use JavaScript to submit the form, so I will naturally access the server.

Form:

 

During the form submission process, I only need to pass the currentPage parameter to JavaScript, so I changed the above connection to the following form:

["+pages[j]+"]

You must note that the document. pagination. currentPage. value = "+ pages [j] +"; written in document. pagination. submit ();, so that before the user submits the form, the parameter currentPage has been changed to the value we need. In this way, I have used the connection to submit the form, but I have encountered a problem. I need to try the above Code on many pages. If I can write a piece of JavaScript in a unified way, I will maintain the entire system in the future, so I have written a JavaScript function.

function submitForm(id,currentPage){//var currentPage = document.pagination.currentPage.value;//alert(currentPage);//currentPage=100;//var currentPage = document.pagination.currentPage.value;//alert(currentPage);document.pagination.currentPage.value=currentPage;var form = document.getElementById(id);form.submit();}

Then I will use this function on the superjoin onclick event:

["+ Pages [j] +"], you can see that the entire code segment is much simpler.

So I summarized it and usedThere are two ways to write a Javascript submission form:(Based on my current understanding)

1. document. formName. submit ();

2. var form = document. getElementById (id );

Form. submit ();

Next time I want to share with you how to implement paging using JNDI. I have attached the code below for your reference.

Commons. js

function submitForm(id,currentPage){//var currentPage = document.pagination.currentPage.value;//alert(currentPage);//currentPage=100;//var currentPage = document.pagination.currentPage.value;//alert(currentPage);document.pagination.currentPage.value=currentPage;var form = document.getElementById(id);form.submit();}

MailingListMemberAdd. jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%><%@ page import="java.util.LinkedList" %><%@ page import="java.util.Iterator" %><%@ page import="java.util.ArrayList" %><%@ page import="java.util.List" %><%@ page import="my.gov.rmp.webmail.domain.User" %><%@ page import="my.gov.rmp.webmail.util.Pager" %>
 Add Member to Mailing List:<%=request.getAttribute("cn")%>

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.