There are three buttons submit the form, how different click of a button, to achieve different actions?

Reprinted from the product is slightly Library  http://www.pinlue.com/article/2020/03/1214/2810021057922.html

ask:

I have three in a form submit button, to achieve different click the button to achieve different operations.

There is no better solution.

In this small section waiting for friends.

Thank you.

______________________________________________________________________________________________

Answer 1:

OnClick then on the button at the beginning of the text is defined javascript = "return calc_form ()" to the steering

function print_form()

{

document.form.action = "print_page.php?id=<?=$id?>";

document.form.target="_blank";

}

function sub_form()

{

document.form.input_ok.value=1;

document.form.action = "buy_list.php?id=<?=$id?>";

document.form.target="";

}

function save_form()

{

document.form.input_ok.value=2;

document.form.action = "buy_list.php?id=<?=$id?>";

document.form.target="";

}

______________________________________________________________________________________________

Answer 2:

The easiest way: write a script for each button

<form id=frm1 name=frm1 method=post action="">

<input id=sendvalue name=sendvalue>

<input type=button id=btn1 name=btn1 οnclick="send1()" value="提交1">

<input type=button id=btn1 name=btn1 οnclick="send2()" value="提交2">

<input type=button id=btn1 name=btn1 οnclick="send3()" value="提交3">

</form>

<script>

function send1(){

frm1.sendvalue = 1;

frm1.submit();

}

function send2(){

frm1.sendvalue = 2;

frm1.submit();

}

...

</script>

______________________________________________________________________________________________

Answer 3:

switch ($submit) {

case "Add":

echo "choice is to add";

break;

case "Delete":

echo "choice is to delete";

break;

case "Rename":

echo "is selected to rename";

break;

}

______________________________________________________________________________________________

A 4:

A form more buttons, to realize the form of sub-script to another method of submission

Posted on February 5, 2010 by admin

<coolcode lang="java script"> <form method="post" action="option.php?action=mailsend_out" id="writemail">

<input type="submit" value="发送邮件" onClick="sendmail()" id="sendmaila">

<input type="button" value="存为草稿" onClick="savedraft();" id="saveddd">

<input type="hidden" name="saveD" value="">

<input type="button" onClick="history.back();" value="返回" id="backhistory">

<script>

function savedraft(){

document.getElementById("saveD").value="savedraft";

//alert(document.getElementById("saveD").value);

document.getElementById("writemail").submit();

}

function sendmail(){

document.getElementById("sendmaila").disabled="disabled";

document.getElementById ( "sendmaila") value = "send, wait ... ...";

document.getElementById("saveddd").disabled="disabled";

document.getElementById("backhistory").disabled="disabled";

document.getElementById("writemail").submit();

}

</script>

</form>

</coolcode>

Where <input type = "hidden" name = "saveD" value = ""> is the key, which is a hidden set of input, pressing a different button assignments to different this hidden value, then option.php? Action = mailsend_out step process as long as the determination of the value it saveD

This entry was posted in javascript categories. The fixed link Add to Favorites.

______________________________________________________________________________________________

Answer 5:

Generally form only a spooler (e.g., CGI program; the ASP program, etc.) corresponding thereto, to process the data form submission.

However, in some cases, we can expect according to the user's option, to the different spooler same form.

That is, the form of points to be submitted. For example, we hope to achieve when users send postings, both when sending submit another preview function, you will encounter the above problems. That is, when the user clicks the submit button, we want the form to be submitted to the "Submit" handler; and when the user clicks on the preview button, we want the form to be submitted to the "Preview" handler. So, how to achieve these functions? The following code can be a good solution to this problem.

<form name="form" method="post">

Test form: <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>

function send () {document.form.action = "send.asp" document.form.submit ()} function preview () {document.form.action = "preview.asp" document.form.submit ()} About above two examples illustrate:

1, the entire form, there should be no action or submit a name for the label, otherwise it will generate an error "Object properties, and this method does not support" (but this is no error in firefox). The code of "<input type =" "xxxx" "name =" "action" ">" is not allowed in the form of;

2, should be present in the form tag name attribute. That is, it should be a name to the form. Statements document.form.action and document.form.submit in the "form" is the name of the form.

Forms of points used in the program to submit only forum, it also can be used in many cases. Proper use of the form to submit sub-functions can greatly enhance the degree of humanity site.

Sometimes the debugger there have been such a problem, there was an error "Object does not support this property and method", it has been unable to locate it, almost mad, but it was because a button to submit the name.

______________________________________________________________________________________________

A6:

A text box are two buttons how to submit data

<script language=javascript>

function ask() {

document.all.dform.action = "ask.asp";

document.all.dform.submit();

}

</script>

<form action="search.jsp" method=get name=dform>

<input type=text>

<input type=submit value="搜索">

<input type=button value="提问" οnclick="cancel();">

</form>

 

 

 

 

 

Published 60 original articles · won praise 58 · Views 140,000 +

Guess you like

Origin blog.csdn.net/yihuliunian/article/details/105308417