Solved

javascript alert

Posted on 2011-09-29
5
305 Views
Last Modified: 2012-05-12
I'm trying to throw an alert if a user leaves a confirmation page without pressing the "place order" button. I found this code that alerts when a user leaves a page:

<script language="JavaScript">
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
  }
</script>

Open in new window


Can someone help me modify it to not alert when the place order button (id="continue) is pressed? And I have some "edit" buttons that take a user back to previous pages. Would be kind of nice if i could add urls to an array of pages that would not alert. I really don't know how to do that though!

Thanks!
0
Comment
Question by:hibbsusan
  • 3
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36815768
your order button :

<input type="button" onclick="stopit=false;" value="Order" />


<script language="JavaScript">
var stopit = true;
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
if( stopit ) {
    return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
}
  }
</script>

Open in new window

0
 

Author Comment

by:hibbsusan
ID: 36816395
so i add

onclick="stopit=false;" 

Open in new window

to every link i want to not get the error when clicked?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36816480
try it

if( false ) {
// nothing happen
    return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
}
0
 

Author Comment

by:hibbsusan
ID: 36816531
um, yeah. that was pretty lazy not to just try it (; sry.

i did now though and it works perfectly. thanks!
0
 

Author Closing Comment

by:hibbsusan
ID: 36894022
thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now