Here is code:
<form method="post" id="cp_ind_form">
// lots of input fields!
<input type="submit" name="update_submit" value="Update" />
<input type="submit" name="delete_submit" value="Delete" onclick="deleteConfirm()" />
</form>
scripts.js (confirmed that this file is connected to above page)
(function deleteConfirm() {
var s = document.getElementById('confirm');
s.onchange = function() {
var yes = confirm('Do you really want to delete this location?');
if (yes) {
var f = document.getElementById('cp_ind_form');
f.submit();
}
}
})();
}
This is driving me insane. Such a basic function is not working here? I am basically copying it from other code that I have that DOES work, and this is no different. Can someone confirm if I am missing a small detail?
Look at the code.
You are adding an onchange event to something when you click the submit.
You are not triggering the confirm to be shown, and you are not cancelling the original submission.
AND it makes no sense to have it wrapped with (funciton(){})();
It should be
and