jQuery Notification When User Want to Leave Changed Form

Fungsi ini berguna untuk memberikan notifikasi kepada user, ketika user sudah mengubah form namun belum menyimpan perubahan tersebut. Penanganannya seperti di wordpress.

[code language=”javascript”]
var formChange = false;
$("form").each(function () {
$(this).find("input, select, textarea").change(function () {
formChange = true;
});
});
$(window).on("beforeunload", function () {
if (formChange) {
return "Perubahan data belum tersimpan.";
}
});
[/code]

Chandra Oemaryadi has written 244 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>