I have a JS client side function that is carrying out a submit when a user clicks on a hyperlink. strURL will point to the page that the user is being sent to.
function SubmitPage(strURL)
{
document.MyForm.method ="POST";
document.MyForm.action = strURL;
document.MyForm.submit();
}
I am trying to confirm that the user wants to leave the current page without saving his data. I am using the OnBeforeUnload event and the code shown below:
function PromptForExit()
{
if (document.MyForm.hidNeedPrompt.value == "Y")
{
event.returnValue ="WARNING: You are about to navigate away from the current page, which may result in data loss."
}
}
And the Body statement looks like this:
<body topmargin=0 leftmargin=0 onBeforeUnload="PromptForExit()">
The event.returnValue works great if the user chooses OK, but results in an error if the user chooses "Cancel" at the prompt.
The error I receive is "A runtime error has occurred. Do you want to debug? Line: 130, Error: Unspecified Error". This line number corresponds to the line containing "document.MyForm.submit();".
Why is the submit still attempting to go forward even after we have stated that we want to Cancel? I am not familiar with the use of event.returnValue, so any help would be greatly appreciated!
function SubmitPage(strURL)
{
document.MyForm.method ="POST";
document.MyForm.action = strURL;
document.MyForm.submit();
}
I am trying to confirm that the user wants to leave the current page without saving his data. I am using the OnBeforeUnload event and the code shown below:
function PromptForExit()
{
if (document.MyForm.hidNeedPrompt.value == "Y")
{
event.returnValue ="WARNING: You are about to navigate away from the current page, which may result in data loss."
}
}
And the Body statement looks like this:
<body topmargin=0 leftmargin=0 onBeforeUnload="PromptForExit()">
The event.returnValue works great if the user chooses OK, but results in an error if the user chooses "Cancel" at the prompt.
The error I receive is "A runtime error has occurred. Do you want to debug? Line: 130, Error: Unspecified Error". This line number corresponds to the line containing "document.MyForm.submit();".
Why is the submit still attempting to go forward even after we have stated that we want to Cancel? I am not familiar with the use of event.returnValue, so any help would be greatly appreciated!