Validation method for multiple submission forms

巴扎黑
Release: 2023-03-02 15:54:02
Original
1459 people have browsed it

Sometimes we need to submit a form from one page to a different page. The processing method is generally to dynamically give the action value in the onClick event, as in the following example:




At this time, the verification of the form for different submission targets can only be placed in the onClick event, but this causes the problem that the form will be submitted regardless of whether it passes verification or not. Because this button is of submit type.

My solution to this problem is this:

<script language="JavaScript"><!--
document.returnValue=true;//一个全局变量,给初值。
function validateForm() { var errors;errors=&#39;&#39;;if (document.PostTopic.title.value=="")errors="标题不能为空";if( document.PostTopic.intro.value.length>10)errors+="\n简介不能多于10个字";if (errors!=&#39;&#39;) alert(errors);document.returnValue = (errors == &#39;&#39;);}
file://--></script>
<FORM ACTION="" METHOD="post" NAME="PostTopic" onSubmit="return document.returnValue;"><input type=text name=title value=""><input type=text name=intro value=""><INPUT TYPE="submit" NAME=Submit VALUE="新增" class=buttonface onclick="document.PostTopic.action=&#39;addone.php&#39;;validateForm(); return document.returnValue;"><INPUT TYPE="RESET" NAME=Reset VALUE="重置" class=buttonface ><INPUT TYPE="submit" NAME="Submit" VALUE="修改" class=buttonface onclick="document.PostTopic.action=&#39;modify.php&#39;;validateForm(); return document.returnValue;"></FORM>
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!