How to run different scripts on different button submits?
Posted: Sun Sep 29, 2013 12:16 pm
Hi,
I have 3 buttons on my form, two which are submits (Confirm and Modify) and one which is just a button for cancel (and a subsequent onClick script when it is clicked).
Currently, there is a piece of code that does the following:
This causes a script to run (pretty much error checking) to ensure that there are checkbox fields selected if the user clicks Confirm to submit the form. However there is no need for the Modify button to run these same checks, so I am looking at ways to avoid the problem I have right now.
One solution I suppose I came up with, but I am not sure if it works, is that I do the modify button similarly to the cancel button and have it run its own onClick script but I am not sure how to write that script such that I can retain all the data like how the current "action='".$_SERVER['PHP_SELF']."" does it in the post array.
A second solution which I am trying to determine if possible is to make the check_num script check if it knows which button was submitted, so it can just return true if it is the modify one, else do the checks if it is confirm one. However again, I am not sure how to do this.
Anyone have any idea on how I can do this? I am not the original author of this code, I just volunteered to help with something for some acquaintances, that's why I seem to be asking questions about things that I should be able to solve if I wrote this code.
Thanks.
I have 3 buttons on my form, two which are submits (Confirm and Modify) and one which is just a button for cancel (and a subsequent onClick script when it is clicked).
Currently, there is a piece of code that does the following:
Code: Select all
echo "<form name='achievement_modify' method='post' onSubmit='return check_num();' action='".$_SERVER['PHP_SELF']."'>";One solution I suppose I came up with, but I am not sure if it works, is that I do the modify button similarly to the cancel button and have it run its own onClick script but I am not sure how to write that script such that I can retain all the data like how the current "action='".$_SERVER['PHP_SELF']."" does it in the post array.
A second solution which I am trying to determine if possible is to make the check_num script check if it knows which button was submitted, so it can just return true if it is the modify one, else do the checks if it is confirm one. However again, I am not sure how to do this.
Anyone have any idea on how I can do this? I am not the original author of this code, I just volunteered to help with something for some acquaintances, that's why I seem to be asking questions about things that I should be able to solve if I wrote this code.
Thanks.