Solved

javascript alert

Posted on 2011-09-29
5
304 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now