Hello, I've written down a small JS function 'checkForm()' to validate the input in a form and alerting, before actually sending data to the PHP server-side script.
In my form, in addition to common input text fields I've got two buttons: the first called "ADD" to submit data and "CANCEL" to abort the insertion, close the form page and come back to the caller.
I've inserted the checkForm() call to the form declaration this way:
<form ... onsubmit="return checkForm()" ... >
Problems comes out when the user doesn't want to finish the form compilation and clicks the "CANCEL" button: void form fields will cause checkForm() to return false, so the submit won't be performed and the page won't be closed, asking the user for useless missing data requirements.
Is there any way to activate checkForm() if and only if the "ADD" button is pressed?
Or some way to detect inside checkForm() which submit button was pressed, so that I can add in the function code a 'return true statement' if I notice the script was called by the "CANCEL" button?