Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: Need to send info to opener of a ModalDialog


Message #1 by "Chris Cote" <cotec@s...> on Thu, 4 Apr 2002 17:46:06
Chris,

Before the Modal Dialog is closed, create an object and define member value
and return the object via window.returnValue.

// In the Modal Dialog
function ReturnIngredient(IngrId, IngrName, retValue)
{
	var oRetIngredient = new Object;
	// Set up the object values
	oRetIngredient.IngrId = IngrId;		
	oRetIngredient.IngrName = IngrName;
	oRetIngredient.Return = retValue;
				
	window.returnValue = oRetIngredient;
	window.close();
}

And in the Main window which popped up this Modal Dialog, get the object as
a return and access the members in the object.

var oRetObject = null;
oRetObject 
window.showModalDialog("Recipe_SelectIngredients.asp?RecType=RET" ,
oIngredient, "dialogWidth:750px; dialogHeight:500px; dialogLeft:100px;");
alert(oRetIngredient.IngrId);
alert(oRetIngredient.IngrName);
alert(oRetIngredient.Return);

The members in the object can also be an array. This works for me in IE, i
am not sure (and not tested) if this works in NN.

Hope it helps..

-Suresh




-----Original Message-----
From: Chris Cote [mailto:cotec@s...]
Sent: Friday, April 12, 2002 11:34 AM
To: JavaScript HowTo
Subject: [javascript_howto] RE: Need to send info to opener of a Modal
Dialog


Hi Suresh,
   I understand this code for sending objects to a modalDialog (to just 
add it as an argument).  However, I'm sorry to say, I'm still not sure how 
to send an object back to the opener window.  My project doesn't need to 
send an object to the popup, but the popup creates an object that is to be 
sent to the main window.  Do I still need to put in the object as an 
argument so that I can get it back?  
   I'm sorry if my questions sound dumb, but I've never done anything like 
this.

Chris


> try this.. I used the following to send objects to modaldialog.. 

From the window to ModalDialog:

var oIngredient = new Object();
oIngredient.IngrCatId = new Array();
oIngredient.IngrId = new Array();
oIngredient.IngrName = new Array();
oIngredient.Mode = "ADD";

// Form the Array elements
var indx = 0;
for ( i=1;i<window.tblIngredients.rows.length;i++)
{
	if (tblIngredients.rows(i).cells(10).children.item(0).value == 1)
	{
		oIngredient.IngrCatId[indx] 
tblIngredients.rows(i).cells(4).children.item(1).value;
		oIngredient.IngrId[indx] 
tblIngredients.rows(i).cells(4).children.item(2).value;
		oIngredient.IngrName[indx] 
tblIngredients.rows(i).cells(4).children.item(0).value;
		indx++;
	}
}

// oRetObject  can be an object returned by window.returnValue from
ModalDialog
oRetObject 
window.showModalDialog("Recipe_SelectIngredients.asp?RecType=RET" ,
oIngredient, "dialogWidth:750px; dialogHeight:500px; dialogLeft:100px;");



In the Modal Dialog:
<SCRIPT Language=javascript>
<!--
	var oIngredient = window.dialogArguments;
	// Access the memebrs of oIngredient as you passed in some function
	function CheckValue()
	{
		for ( i=0;i<oIngredient.IngrCatId.length;i++)
		{
		oOption = document.createElement("OPTION");
		oOption.value = oIngredient.IngrCatId[i] + "-" +
oIngredient.IngrId[i];
		oOption.text = oIngredient.IngrName[i];
		window.cboSelectedIngredient.options.add(oOption);
		}
	}

//-->
</SCRIPT>


using the same procedure you could send back values from Modal Dialog to
opener window. 

Hope it makes sense..

Suresh

---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20



"The information in this email, and in any attachments,
may contain confidential information and is intended 
solely for the attention and use of the named addressee(s).
It must not be disclosed to any person without authorization.
If you are not the intended recipient, or a person responsible for
delivering it to the intended recipient, you are not authorized
to, and must not, disclose, copy, distribute, or retain this
message or any part of it."

  Return to Index