PC Review


Reply
Thread Tools Rate Thread

Check form before unload for changes

 
 
Assimalyst
Guest
Posts: n/a
 
      10th Aug 2005
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;
}

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      10th Aug 2005
onCheckChanged is a server-side event handler. You need this to add a client
side handler:

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

Eliyahu

"Assimalyst" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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;
> }
>



 
Reply With Quote
 
Assimalyst
Guest
Posts: n/a
 
      11th Aug 2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing Access While Form Is In Print Preview Does Not Trigger Form Unload Event Stewart Berman Microsoft Access Form Coding 3 7th Jun 2010 03:15 AM
Check box Msg for eight boxes on the Unload event. =?Utf-8?B?b3hpY290dGlu?= Microsoft Access Form Coding 3 16th Feb 2007 02:10 AM
Unload a form Peter Microsoft Dot NET Framework Forms 1 4th Dec 2003 11:16 PM
Form Unload Khai Microsoft Excel Programming 0 4th Aug 2003 09:28 PM
Re: Unload form, load another, forget about original form Bob Microsoft VB .NET 1 9th Jul 2003 01:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:26 AM.