My favorites | Sign in
Project Logo
                
Search
for
Updated Aug 23, 2008 by subimage
Labels: Featured
UsingCallbackFunction  
Using callback functions with SubModal
  1. Define the function that’ll be called on the opening page.
  2. Pass the function you’d like to call into 'showPopWin'.
  3. Assign any return value on the modal page itself, if necessary
  4. Call the hidePopWin function passing true

It might be easier to grok in code, so here's an example:

On the SubModal opening page

// returnVal can get passed in from the modal page itself...
//....see below for info
function returnRefresh(returnVal) {
  window.document.reload();
}

// Open the modal, passing in the refresh function 
// as a reference NOT a string.
showPopWin('mymodal.html', 500, 500, returnRefresh);

From inside the SubModal window

// If you plan to pass a return value assign it
var returnVal = "something";

// When you're ready to close the pop window 
// call this...Passing true makes sure the return 
// function gets called.
window.top.hidePopWin(true); 

Comment by r...@rq.lt, Mar 16, 2009

returnRefresh() should use window.location.reload() instead of window.document.reload().

Comment by luizaugusto3b, May 01, 2009

I didn't get to put the variable. var returnVal stay in my modal window

Comment by Blitzxion, May 06, 2009

@luizaugusto3b

I'm having the same problem. How come the "returnVal" value just stays with the modal window. I have a simple textbox that someone can type in (in the modal window), when they press submit I want the typed text to appear in the parent window. Everytime I try, i get nothing. Anyone know what i'm doing wrong?

Comment by luizaugusto3b, Jun 03, 2009

Blitzxion I tried to put my modal window only same file, but this solution isn´t ideal.

when i try to use my modal in a page using internet explorer 6.0, the select box show in my middle modal window, and a I can´t hide this select, Do anyboby know how to hide this select?

P.S.: I saw at the script a place where it handle this error in code, but my bug wasn´t fixed.

Comment by jamsoo, Jul 29, 2009

In order for the "returnVal" to return variables, the "returnVal" should be declared as following... inside the subModal window. I wish this helps....

<script language="javascript">

var returnVal = "none";

function ClosePopupWin ( )
{
	returnVal = "here is my return value!!!";
	window.top.hidePopWin(true);
}

</script>
Comment by zorbaleeroper, Sep 05, 2009

I can't get returnVal back, either. When I try to access it using a simple alert in the callback function, the alert doesn't fire. If I replace the returnVal variable, the alert fires and displays whatever string I use. I've assigned returnVal just as you've shown, but for some reason it isn't being set.

Comment by sakalou, Sep 18, 2009

How to provide some value to modal window. For example goal is to show help message. Like "This is that ... ". So message itself should be passed in modal screen.

Comment by liceblone, Sep 23, 2009

<button onclick="showPopWin('modalContent.html', 600, 450, showmessage,true);">show modal window button</button>

function showmessage(returnVal) {alert(returnVal);}

i cannot get the return value. so is there anyone can tell me how to set return value

Comment by zorbaleeroper, Sep 29, 2009

The way I've gotten around the returnVal problem is simply by doing this:

window.top.action = "whatever you want to return"

It works in both IE7 and FF3. I would think it would work in earlier versions as well.

zorba...

Comment by kamakazi27, Nov 25, 2009

Just for people like me who wondered, returnVal can be an array, for example, in my case

    function buildReturnArray() {
      user = document.getElementById("userField").value;
      password = document.getElementById("passwordField").value; 
      returnVal = new Array(user,password);
    }
Comment by vivoart2, Dec 01, 2009

I'm brand new at this. All I want is the pop up modal to have Accept or Don't Accept buttons. If the terms in the modal box are accepted by clicking accept, the visitor is taken inside the site (a .php link). If not accepted the visitor is taken to away from the website. How is this possible. The code above unlike the previous code for the modal box does not explain where it must be pasted and where to insert links if any, also where does the Showpopwin get inserted?


Sign in to add a comment
Hosted by Google Code