Loan - Wordpress Themes - Infrared Sauna - Wordpress Themes - Debt Consolidation

PDA

View Full Version : which button has been pressed?


Jamie18
Aug 15th 2007, 1:46 pm
i want to use javascript to figure out which submit button has been pressed, cancel or update, before i run the form validation onsubmit..

i.e.
html

<form .. onsubmit="checkcomplete()">
<input type="submit" value="cancel">
<input type="submit" value="update">
.....
</form>

javascript pseudo

function checkcomplete
{
if cancel button clicked
return false
else
return results of form validation tests
}

any way to determine which button has been pressed?

nhl4000
Aug 15th 2007, 2:57 pm
You can do the following
<input type="submit" value="Cancel" onclick="checkcomplete('Cancel');">
<input type="submit" value="Update" onclick="checkcomplete('Update');">

Jamie18
Aug 16th 2007, 6:03 am
so i would than remove the onsubmit from the form tag?

would the result of the checkcomplete function still determine whether or not the form is submitted? or would it simply do the check than submit regardless?

you have given me an idea though.. if the onclick of the button works before the onsubmit of the form i could call a function to set a variable to either cancel or confirm and use that in the checkcomplete function.

anyways, thanks for the help