...

View Full Version : Cannot successfully pass data from popup to parent



JME
08-27-2008, 09:45 PM
I have followed directions from other websites on how to code to successfully pass data from a popup to a parent page but I cannot get the data to display on the parent page. Hoping someone can give me the missing link.

Here are my code snippets (BTW I am working with coldfusion but the passing code is javascript):

Parent page:


<cfform id="frmRelease" name="frmRelease" method="post" preservedata="yes" action="preview.cfm?action=edit" enctype="multipart/form-data" onsubmit="return submitForm();">

//hidden field that should hold the passed data. I have debug code that should show me the passed data once the page reloads but I never get the passed data displayed.

<input type="hidden" name="contactListing" />
<cfif isDefined("form.contactListing")><cfoutput> this is contact list #form.contactListing#</cfoutput><cfelse><cfoutput>there is no contact list </cfoutput></cfif>


<script language="JavaScript 1.2" type="text/javascript">
<!--
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=500,left = 190,top = 62');");
}

</script>


//where I call the popup
<legend>Contact &nbsp;&nbsp; <a href="javascript:popUp('contactList.cfm?id=<cfoutput>#releaseID#</cfoutput>&page=edit')">Select Contacts</a></legend>

Popup page:
//The page displays a number of selections for the user. I then collect the data on submit and create a variable to pass the data back to the parent. I have debug alerts that show me I do have data before I transfer and that I supposedly successfully transfer the data.

<cfform id="frmContact" name="frmContact" method="post" preservedata="yes" onsubmit="submitForm();window.close();">
<input type="hidden" name="contactList" />
<script language="javascript">
function submitForm()
{
alert("i am here");
var numContacts = document.frmContact.numberOfContacts.value;
for(i=1;i<=numContacts;i++){
if(eval('document.frmContact.order' + i + '.value')!=''){
if(isNaN(eval('document.frmContact.order' + i + '.value'))){
eval('document.frmContact.order' + i + '.select()');
alert('Please enter a proper value in the order box');
return false;
}
}
}
var contactArray=new Array();
var contactCounter = 0;
var passBackContacts = "";
for (i=1;i<=document.frmContact.numberOfContacts.value; i++){
if (passBackContacts != ""){
passBackContacts = passBackContacts + "," ;
}
if(eval('document.frmContact.order' + i + '.value')!=''){
contactCounter = contactCounter++;
contactArray[contactCounter] = eval('document.frmContact.order' + i + '.value')+","+eval('document.frmContact.contactID' + i + '.value');
passBackContacts=passBackContacts + eval('document.frmContact.order' + i + '.value');
}
else {
passBackContacts=passBackContacts+"0";
}
}
alert("test that we have data passbackcontacts = "+passBackContacts);
window.opener.document.frmRelease.contactListing.value =passBackContacts;
alert("after assignment");
opener.location.reload();
}
</script>

shyam
08-28-2008, 05:46 PM
it doesn't matter what server-side language you are using. just post the generated html

JME
08-28-2008, 07:51 PM
generated HTML for parent - stripped to include only pertinent info

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html lang="en-us">
<head>
<script language="JavaScript" type="text/javascript" src="html2xhtml.js"></script>
<script language="JavaScript" type="text/javascript" src="richtext_compressed.js"></script>


<script LANGUAGE=JAVASCRIPT TYPE="text/javascript" >

<!--

function _CF_checkfrmRelease(_CF_this)

{

return submitForm();

return true;

}


//-->

</script>

</head>

<body>


<FORM NAME="frmRelease" ACTION="preview.cfm?action=edit" METHOD=POST onSubmit="return _CF_checkfrmRelease(this)" ENCTYPE="multipart/form-data" ID="frmRelease">

<input type="hidden" name="releaseID" value="28" /> this is releaseid 28

<input type="hidden" name="contactListing" />
there is no contact list


<script language="JavaScript 1.2" type="text/javascript">
<!--
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=500,left = 190,top = 62');");
}



</script>


<legend>Contact &nbsp;&nbsp; <a href="javascript:popUp('contactList.cfm?id=28&page=edit')">Select Contacts</a></legend>

</FORM>







</body>
</html>














generated HTML for Popup - stripped to include only pertinent info

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<html lang="en-us">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script language="javascript">
function submitForm()
{
var numContacts = document.frmContact.numberOfContacts.value;
for(i=1;i<=numContacts;i++){
if(eval('document.frmContact.order' + i + '.value')!=''){
if(isNaN(eval('document.frmContact.order' + i + '.value'))){
eval('document.frmContact.order' + i + '.select()');
alert('Please enter a proper value in the order box');
return false;
}
}
}
var contactArray=new Array();
var contactCounter = 0;
var passBackContacts = "";
for (i=1;i<=document.frmContact.numberOfContacts.value; i++){
if (passBackContacts != ""){
passBackContacts = passBackContacts + "," ;
}
if(eval('document.frmContact.order' + i + '.value')!=''){
contactCounter = contactCounter++;
contactArray[contactCounter] = eval('document.frmContact.order' + i + '.value')+","+eval('document.frmContact.contactID' + i + '.value');
passBackContacts=passBackContacts + eval('document.frmContact.order' + i + '.value');
}
else {
passBackContacts=passBackContacts+"0";
}
}
alert("test that we have data passbackcontacts = "+passBackContacts);
window.opener.document.frmRelease.contactListing.value =passBackContacts;
alert("after assignment");
opener.location.reload();
}
</script>



<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>


<script LANGUAGE=JAVASCRIPT TYPE="text/javascript" >

<!--

function _CF_checkfrmContact(_CF_this)

{

submitForm();window.close();

return true;

}


//-->

</script>

</head>

<body>
<FORM NAME="frmContact" METHOD=POST onSubmit="return _CF_checkfrmContact(this)" ID="frmContact">

<table>
<tr>
<th align="center">Contact</th>
<th align="center">Order</th>
</tr>

<input type="hidden" name="contactID1" value="1"/>
<tr>
<td><label for="order1" class="shortLabel">&nbsp;&nbsp;Kevin&nbsp;Hall</label></td>
<td><input type="text" size="1" name="order1" /></td>
</tr>

<input type="hidden" name="contactID2" value="6"/>
<tr>
<td><label for="order2" class="shortLabel">&nbsp;&nbsp;Delacey&nbsp;Skinner</label></td>
<td><input type="text" size="1" name="order2" /></td>
</tr>

<input type="hidden" name="contactID3" value="7"/>
<tr>
<td><label for="order3" class="shortLabel">&nbsp;&nbsp;Charles&nbsp;Pyle</label></td>
<td><input type="text" size="1" name="order3" /></td>
</tr>

<input type="hidden" name="contactID4" value="8"/>
<tr>
<td><label for="order4" class="shortLabel">&nbsp;&nbsp;Kathy&nbsp;Glazer</label></td>
<td><input type="text" size="1" name="order4" /></td>
</tr>

<input type="hidden" name="contactID5" value="9"/>
<tr>
<td><label for="order5" class="shortLabel">&nbsp;&nbsp;Shea&nbsp;Hollifield</label></td>
<td><input type="text" size="1" name="order5" /></td>
</tr>

<input type="hidden" name="contactID6" value="10"/>
<tr>
<td><label for="order6" class="shortLabel">&nbsp;&nbsp;Kelly&nbsp;Lobanov</label></td>
<td><input type="text" size="1" name="order6" /></td>
</tr>

<input type="hidden" name="contactID7" value="11"/>
<tr>
<td><label for="order7" class="shortLabel">&nbsp;&nbsp;Christie&nbsp;Collins</label></td>
<td><input type="text" size="1" name="order7" /></td>
</tr>

<input type="hidden" name="contactID8" value="12"/>
<tr>
<td><label for="order8" class="shortLabel">&nbsp;&nbsp;Jeff&nbsp;Kraus</label></td>
<td><input type="text" size="1" name="order8" /></td>
</tr>

<input type="hidden" name="contactID9" value="13"/>
<tr>
<td><label for="order9" class="shortLabel">&nbsp;&nbsp;Bob&nbsp;Spieldenner</label></td>
<td><input type="text" size="1" name="order9" /></td>
</tr>

<input type="hidden" name="numberOfContacts" value="9">


</body>
<p><input type="submit" name="submit" value="Accept Changes">&nbsp; &nbsp;<input type="submit" value="Cancel" name="btnCancel" onClick="javascript:window.close();">
</p>
</FORM>
</html>

rangana
08-29-2008, 06:38 AM
I see that the data is being passed correctly.

Try to change highlighted to text (temporarily) to see the value:


<input type="hidden" name="contactListing" />

JME
08-29-2008, 03:16 PM
Found that it is a problem with the reload - what I want to be able to do is use the data passed to create a results display on the parent page. To do that I was looking to reload the page, utilize the data to get info from a database and then display the results on the parent page. But it appears that the reload is not able to read the value of the hidden field and/or does not retain the value for redisplay.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum