Solved

onclick cancel another function

Posted on 2011-09-25
6
300 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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to count occurrences of each item in an array.

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

24 Experts available now in Live!

Get 1:1 Help Now