Solved

javascript alert

Posted on 2011-09-29
5
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

630 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