Solved

onclick cancel another function

Posted on 2011-09-25
6
305 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
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

688 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