Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

javascript alert

Posted on 2011-09-29
5
Medium Priority
?
313 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 83

Accepted Solution

by:
leakim971 earned 2000 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 83

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

885 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