|
Today I encountered a problem, the page includes a lot of public pages (all without form), and many places in it are self-submitted (add a type="submit" field to the page, and then write sumbit.click in js to execute the commit). But I need to verify whether the filling in the form meets the requirements before each submission, and if I add a call to the validation function to each submission, it will be a lot of work. I need to do something about it, which is to verify the form uniformly before submitting it. From the body has the event onbeforeunload before the page is closed, it is inferred that the form should also have a pre-commit eventonsubmit。 The function of this event is to automate the execution of the specified thing before the form is submitted. It should be noted that the return in onsubmit="return check()" must be added, otherwise even if the return value of check is false, it will still be submitted. That is, onsubmit="return false" is not to execute the commit; onsubmit="return true" or onsubmit="return" both execute the commit; ------------------------------------------ The main page is as follows: <HTML> <HEAD> <scrip{filter}t type="text/javascrip{filter}t"> //form提交前,验证:营销活动最少选择两个 function check(){ if(validation condition fails) { return false; }else{ return true; You can also not write this return value, and you can submit it directly }
} </scrip{filter}t> </HEAD> <body> <form id="queryForm" onsubmit="return check()" action="<%=request.getContextPath()%>/FocReportServlet"> <jsp:include flush="true" page="../pub.jsp"/> <jsp:include flush="true" page="../condition.jsp"/> <jsp:include flush="true" page="condition_marketing.jsp"/> <jsp:include flush="true" page="contrastChart.jsp"/> <jsp:include flush="true" page="../pagectrl.jsp"/> ... <input type="submit" id="submit" name="submit" style="visibility:hidden"/> <HTML> ----------------------------------- include page: <img src="<%=request.getContextPath()%>/focReport/images/control_play_blue.png" style="cursor:hand"#323e32" face="simsun">submit.click()" alt="Click to submit analysis" >
|