[Turn] document.form.action, form sub-submission

document.form.action, form sub-submission, javascript submit form  

The same form can be submitted to different spoolers depending on the user's selection. That is, the sub-submission of the form. For example, when writing a forum program, if we want to implement both the submit function and the preview function when users send posts, they will encounter the above problems. That is, when the user clicks the submit button, we want the form to submit to the "submit" handler; and when the user clicks the preview button, we want the form to submit to the "preview" handler. So, how to achieve the above function? The following code can solve this problem very well.

<form name="form" method="post">  
测试表单:<input name="test"><br>  
<input type="button" value="提交" onClick=send()>  
<input type="button" value="预览" onClick=preview()>  
</form>  
<script language=javascript>  
function send()  
  {  
    document.form.action="send.asp"  
    document.form.submit()  
   }  
function preview()  
   {  
     document.form.action="preview.asp"  
     document.form.submit()  
   }  
</script>  

Two notes about the above example:   

 1. In the entire form, there should not be a label named action or submit, otherwise an error of "object does not support this property and method" will be generated. For example, the code " < input  type= 'xxxx'  name= 'action'  >" is not allowed in the form;   2. The name attribute should exist in the form tag . That is, the form should be given a name. The "form" in the statements document.form.action and document.form.submit is the name of the form.  

 Submission of forms is not only used in forum programs, it can also be used in many situations. Appropriate use of the form's sub-submission function can greatly enhance the humanization of the website.   

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325152027&siteId=291194637