|
UsingCallbackFunction
Using callback functions with SubModal
Featured
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); |
► Sign in to add a comment
returnRefresh() should use window.location.reload() instead of window.document.reload().
I didn't get to put the variable. var returnVal stay in my modal window
@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?
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.
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>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.
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.
<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
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...
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); }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?
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
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) { }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
this function is very userful. you can hit this link to get an example: http://www.alcooo.com/