My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
UsingCallbackFunction  
Using callback functions with SubModal
Featured
Updated Feb 4, 2010 by subim...@gmail.com
  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 luizaugu...@gmail.com, May 1, 2009

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

Comment by Blitzx...@gmail.com, May 6, 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 luizaugu...@gmail.com, Jun 3, 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 jam...@gmail.com, 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 zorbalee...@gmail.com, Sep 5, 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 saka...@gmail.com, 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 licebl...@gmail.com, 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 zorbalee...@gmail.com, 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 kamakaz...@gmail.com, 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 vivoa...@gmail.com, Dec 1, 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?

Comment by sac....@gmail.com, Mar 25, 2010

For any one having problems with return value please have a look here.

http://www.chrismay.org/2006/11/29/Adding+Return+Values+To+SubModal.aspx

or the code below

In your "main" html page, declare a callback function and a button that will launch the modal dialog:
function myFunction(val){
alert("Return value is..."); alert(val);

Then create an input button to launch the modal dialog.

<input type="button" onclick="showPopWin('modalcontent.html', 400, 200, myFunction);"

Then, in the submodalsource file, or where ever you have your JS stored, change this function to include a return value, and have it use it.

/

  • @argument callReturnFunc - bool - determines if we call the return function specified
  • @argument returnVal - anything - return value
function hidePopWin(callReturnFunc, returnVal) {
//alert(callReturnFunc); gPopupIsShown = false; restoreTabIndexes(); if (gPopupMask == null) {
return;
} gPopupMask.style.display = "none"; gPopupContainer.style.display = "none"; if (callReturnFunc == true && gReturnFunc != null) {
// edited by CDM -- gReturnFunc(window.frames["popupFrame"].returnVal); gReturnFunc( returnVal );
} gPopFrame.src = gLoading; // display all select boxes if (gHideSelects == true) {
displaySelectBoxes();
}
}

Then finally on your modal page, just some code to close the window, and pass back the return value.

<button onclick="window.parent.hidePopWin(true, 'I am the return value')">close

Comment by zgc....@gmail.com, May 17, 2010

this function is very userful. you can hit this link to get an example: http://www.alcooo.com/


Sign in to add a comment
Powered by Google Project Hosting