Reputation: 11652
based on this post I am asking confirmation from user to save data before leaving the page,if user enter any data in the textfields.
but I am getting below error when page loads and my form id is "Form1"
<script type="text/javascript" language="javascript">
window.onload = function (e) {
var form_has_been_modified = 0;
$("form[id^='Form1']").on("change keyup", ":input", function () {
form_has_been_modified = 1;
})
};
window.onbeforeunload = function (e) {
if (!form_has_been_modified) {
return;
}
var message = "Do you want to save the data before leave the page?";
var e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = message;
}
// For Safari
return message;
};
</script>
how to solve this issue?
Updated: in HTML source code shows <form name="aspnetForm" method="post" action="EditMember.aspx?Id=3664653" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm" enctype="multipart/form-data">
, How to use this form in above code?
Upvotes: 0
Views: 1042
Reputation: 1063
Your selector is wrong
$("form[id^='Form1']") Should be $("#Form1")
Also don't forget there might be more then just input tags (select and textarea for example)
Upvotes: 0