Building permit applicants in my municipality can go to the website and fill out a pdf form. When they click on the submit form button I want the user to be asked if they want to save it first.
Here's how you can do that using jQuery:
https://jsfiddle.net/ze9Lm9s8/2/
JS
$(document).ready(function(){
$("#my-form input[type=submit]").on("click", function(e){
//Make sure it doesn't submit by default
e.preventDefault();
//Ask if user would like to save
var r = confirm("Would you like to save changes?");
if (r == true) {
//Do your stuff here
$("#my-form").submit();
} else {
alert('Submission aborted');
}
});
});
HTML
<form id="my-form" action="/" method="POST">
<input type="submit" value = "submit"/>
</form>
Keep in mind that browser's native confirmation dialog is not reliable so you might want to get a js implementation instead of it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.