Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Check form before unload for changes (http://www.velocityreviews.com/forums/t107817-check-form-before-unload-for-changes.html)

Assimalyst 08-10-2005 02:22 PM

Check form before unload for changes
 
Hi,

I have a javascript that checks a form for changes, if it has any it
alerts the user before they navigate away from the page.

it can be disabled on a submit button click by adding

onclick="Javascript:bSubmitted=true;"

to it's tag.

However i have a checkbox that has AutoPostBack=true and would like to
disable it for that too, but if i add

onCheckChanged="Javascript:bSubmitted=true;"

I get a compilation error when the page loads

CS1026: ) expected

Can anyone suggest a fix? The javascript is below, just incase it's
useful.

Thanks

function checkFormStatus(oForm){
if(isDirty(oForm))
event.returnValue = "You have entered form Data without submitting this
form.";
}

var bSubmitted=false;
function isDirty(oForm)
{
if(bSubmitted) return false;
var iNumElems = oForm.elements.length;
for (var i=0;i<iNumElems;i++)
{
var oElem = oForm.elements[i];

if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
{
if (oElem.value != oElem.defaultValue) return true;
}
else if ("checkbox" == oElem.type || "radio" == oElem.type)
{
if (oElem.checked != oElem.defaultChecked) return true;
}
else if ("SELECT" == oElem.tagName)
{
var oOptions = oElem.options;
var iNumOpts = oOptions.length;
for (var j=0;j<iNumOpts;j++)
{
var oOpt = oOptions[j];
if (oOpt.selected != oOpt.defaultSelected) return true;
}
}
}
return false;
}


Eliyahu Goldin 08-10-2005 03:44 PM

Re: Check form before unload for changes
 
onCheckChanged is a server-side event handler. You need this to add a client
side handler:

myCheckBox.Attributes["onclick"] = "Javascript:bSubmitted=true;";

Eliyahu

"Assimalyst" <c_oxtoby@hotmail.com> wrote in message
news:1123683751.021984.222320@g49g2000cwa.googlegr oups.com...
> Hi,
>
> I have a javascript that checks a form for changes, if it has any it
> alerts the user before they navigate away from the page.
>
> it can be disabled on a submit button click by adding
>
> onclick="Javascript:bSubmitted=true;"
>
> to it's tag.
>
> However i have a checkbox that has AutoPostBack=true and would like to
> disable it for that too, but if i add
>
> onCheckChanged="Javascript:bSubmitted=true;"
>
> I get a compilation error when the page loads
>
> CS1026: ) expected
>
> Can anyone suggest a fix? The javascript is below, just incase it's
> useful.
>
> Thanks
>
> function checkFormStatus(oForm){
> if(isDirty(oForm))
> event.returnValue = "You have entered form Data without submitting this
> form.";
> }
>
> var bSubmitted=false;
> function isDirty(oForm)
> {
> if(bSubmitted) return false;
> var iNumElems = oForm.elements.length;
> for (var i=0;i<iNumElems;i++)
> {
> var oElem = oForm.elements[i];
>
> if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
> {
> if (oElem.value != oElem.defaultValue) return true;
> }
> else if ("checkbox" == oElem.type || "radio" == oElem.type)
> {
> if (oElem.checked != oElem.defaultChecked) return true;
> }
> else if ("SELECT" == oElem.tagName)
> {
> var oOptions = oElem.options;
> var iNumOpts = oOptions.length;
> for (var j=0;j<iNumOpts;j++)
> {
> var oOpt = oOptions[j];
> if (oOpt.selected != oOpt.defaultSelected) return true;
> }
> }
> }
> return false;
> }
>




Assimalyst 08-11-2005 09:48 AM

Re: Check form before unload for changes
 
Thanks for the suggestion, but i'm pretty new to all this.

Could you explain in a little more detail how to do this? I can't get
it to work.

Thanks again.



All times are GMT. The time now is 08:23 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.