Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to call two different files with one form

Status
Not open for further replies.

spookie

Programmer
May 30, 2001
655
IN
hi all,
i have a form which has two submit buttons.
i want to call two different PHP files/scripts depending upon the submit user clicks.
i knpw it can be done thru javascript using location.href
trapping onclick event.
how this can be done in PHP?
thanks in advance.
spookie
 
You can have one form for each submit button, and have the form action point to the target script for that button,

OR

you can include both buttons in the same form and have the action for that form POST back into the same script, and at the top of that script figure out which button was pressed and redirect to the right target script.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
<script language=javascript>
function doValidation(ButtonClicked){
if(ButtonClick.value == &quot;Button1&quot;){
document.forms[0].action = &quot;pageforbutton1.php&quot;;
}else if(ButtonClick.value == &quot;Button2&quot;){
document.forms[0].action = &quot;pageforbutton2.php&quot;;
}
document.forms[0].submit();
}
</script>

<form method=post>
<input type=button name=Button1 onclick=&quot;javascript:doValidation(this.form.elements['Button1']);&quot; value=Button1><br>
<input type=button name=Button2 onclick=&quot;javascript:doValidation(this.form.elements['Button2']);&quot; value=Button2>
</form>
Chad
tinman@thelandofoz.org

Tinman,

Welcome to OZ.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top