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
Solved

onclick cancel another function

Posted on 2011-09-25
6
303 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

861 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