I have a main page with a js variable. I want to open a modal on that main page and load html content from a different page. I need to pass that variable to the modal that is opening and use it inside the loaded html content. I have seen several questions similar to that in these forums but i don't see any that explain how I can tease that variable out of the loaded html content. I know that i can make a GET request for that external html content, and I know that i can include the variable in the query string. But how do i get it out of the query string inside the modal? All of the examples i see for getting things out of query string involve using window.location.href or something similar. Well that won't work for me because that returns the url of the main page I am on and not my modal popup. Any suggestions?
VBA - I'd normally use the $("#mypopupdiv").dialog() function and then populate #mypopupdiv with values derived via a $ajax call. you'd store your $var at module level and then when the popup was loading (or loaded, depending on your processing requirements), you'd put the variable to use. The beauty of the .dialog() method is that altho it's a popup, it's actually part of the parent page, rather than being a seperate process.
with careful consideration, this is very reliable and effective and can be used in a wide variety of scenarios without side-effect.
further details if required.
jim
VBA, to keep the popup div 'self-contained' and not using the global var, you could do the following:
$("#mypopupdiv").data("userid", $varUserId);
then, in the popup populate code, you'd 'grab' that data:
if ($("#mypopupdiv").data("userid") != null) {
// do some stuff with it
}
other ways to skin the cat abound, but just another one to throw to the wind...
jim
I got it to work but I'm not sure how or why. In my main page I utilize my jQuery plugin which is named jquery.contacts.js. I set a few default values on that plugin then i give it a div and call the contacts method.
$.fn.contacts.defaults.currentUser = _currentUser;
if (!$("#searchContactDialog").contacts()) {
return false;
}
This pulls in the external content and loads it into the div. Now when I run the js that is inside that injected content I can ref a variable named contacts and get at those defaults.
_userId = $(this).contacts.defaults.currentUser;
I was not expecting that contacts var to be available to me and I'm not sure how it is so. In fact I'm a little confused as to what $(this) represents in that line of code. But it works...