Solved

onclick cancel another function

Posted on 2011-09-25
6
301 Views
Last Modified: 2012-05-12
I have a function that runs onunload.
Is there a way that when someone clicks a different button on the page, and it runs a different function, is there a way to cancel and make sure the onunload won't run?
0
Comment
Question by:rivkamak
  • 3
  • 2
6 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36596513
>is there a way to cancel and make sure the onunload won't run

use a input with type = button
and not a submit button

set the onclick attribute of this button to run the different function
0
 
LVL 12

Expert Comment

by:zappafan2k2
ID: 36596514
Try adding
window.onunload=null;

Open in new window

somewhere in your function to cancel the onunload call.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36596515
<input type="button" onclik="a_different_function()" value="no unload" />

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 12

Expert Comment

by:zappafan2k2
ID: 36596522
leakim971,

I think rivkamak is looking for a way to cancel the onunload call.  There seems to already be a function called when a button is clicked.

In your example (onclik should be onclick, I think), in  a_different_function() adding the line I posted above would cancel the onunload function.
0
 

Author Comment

by:rivkamak
ID: 36596786
My onlick submits the page. But I don't want the onunload to happen when you click the submit button.
If the form submits but I put value="no unload", then the unload wont' happen?
0
 
LVL 12

Accepted Solution

by:
zappafan2k2 earned 250 total points
ID: 36598861
Try something like this
<script type="text/javascript">
function cancelUnload() {
    window.onunload = null;
    return true;
}
</script>

...

<input type="submit" value="Submit" onClick="return cancelUnload();" />

Open in new window


The value property of your submit button will not affect anything.

If you already have a function that gets called with the onclick, then add the line
window.onunload=null;

Open in new window

to that function, as I suggested above.

If this doesn't help you, then post the code you're using.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Tool to Build Android and iOS App 3 55
Change javascript css 1 21
How to write an English digest paper 6 25
how to avoid redundand ajax calls 5 11
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

863 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

22 Experts available now in Live!

Get 1:1 Help Now