Issue with two submit buttons
HTML FORM looks like below:
- <form id="biz" name="biz" action="CGI.script" method="post" onSubmit="console.log('submit button, not save button, clicked'); if (document.getElementById('field1').value=='$'){alert('Liability is required');return false} else if (document.getElementById('field2').value=='$'){alert('Fee is required'); return false};">
- form field 1
- form field 2
- form field n
- ...
- lots of fields...
- <input type="submit" id="save-and-continue" name="saveandcontinue" value="Save & Continue" onclick="saveData(this.form);">
- <span id="inform" style="color:red"></span>
- <input type="submit" id="saveform" name="saveform" value="Save & Exit">
- </form>
- Javascript looks like this:
- <script>
- function saveData() {
- // use jQuery to send form save data via ajax call
- ...
- // it works fine
- return false
- }
- </script>
Intention:
As the names suggest, "Save & Continue" is supposed to save the data and the form stays on while "Save & Exit" is supposed to send the form to be processed (and we leave this page).
Use Scenario and Problem Statement:
If I load the page and enter some data and click on the "Save & Exit", fine, it works as expected.
But if I enter/edit data, click on "Save & Continue" (jQuery ajax call works fine to save data and stay on the page), and but then, after more data entry/editing click on "Save & Exit", it triggers the "Save & Continue" event instead of submitting the form and leave the page.
How can we resolve it?
Thanks.