PDA

View Full Version : Which Button was clicked?



jdc
10-17-2005, 06:40 PM
Hey all, first post and couldn't find any related questions...

I have a form with an onsubmt="return validateForm()"...

I have two buttons: A Modify and a Delete. I have a validateForm function. In my function, how can I tell which button was clicked.

<form name="form1" action="<?= $PHP_SELF ?> method="POST" onsubmit="return validateForm()">

... form stuff ....
<input type="submit" name="modify" value="modify">
<input type="submit" name="delete" value="delete">

What I want to do is, when the delete button is clicked, provide the user with a messagebox stating, "You are about to delete a record, do you want to procede?"

if Yes is clicked, process the form.

Any thoughts.

Thanks,
jdc

mwinter
10-17-2005, 08:28 PM
What I want to do is, when the delete button is clicked, provide the user with a messagebox stating, "You are about to delete a record, do you want to procede?"

if Yes is clicked, process the form.If the confirmation is important, then it should be done through a server-side mechanism, just like input validation. Alternatively, make the user perform two actions so it won't be accidental: selecting a check box then a button, for instance. The final option would be to make the action reversible; a list of 'Trash'.

If you really must do this client-side, then the confirmation action must be added directly to the button as that's the only way to determine which was clicked.


function confirmDelete() {
return confirm('Are you sure you want to delete this entry?');
}
<input name="modify" type="submit" value="Modify" onclick="return confirmDelete();">Mike