I have a child window with email address in a form that I want to pass onto my parent window with a form. I am getting an error saying, "opener.document.formname is undefined". where "formname" is a variable that I passed in the javascript script call on the parent form which is then used by the javascript form on the child form.
Here is my code below. You'll notice coldfusion variables since my forms are dynamically created based on database records. However, I have added an alert on the child javascript function and my variable appear to be passing correctly to the child form.
This is the form code in the parent window:
This is the javascript code on the parent window:
Here is the portion of form code in the child window that calls the javascript function:
Here is the javascript function in the child window that is posting the selected values in the child form back to the parent form. The form type passed from the parent form is "statusnotes":
Here is my code below. You'll notice coldfusion variables since my forms are dynamically created based on database records. However, I have added an alert on the child javascript function and my variable appear to be passing correctly to the child form.
This is the form code in the parent window:
Code:
<form id="statuscomment#id#" name="statuscomment#id#" method="post" action="projectstatus.cfm" style="margin-bottom:0;">
Status Meeting Comments: <br>
<input type="hidden" name="mode" value="editstatusmeeting">
<input type="hidden" name="statusdetailid" value="#id#">
<input type="hidden" name="projectid" value="#projectid#">
<input type="hidden" name="attendees" value="usersselected">
<input type="hidden" name="selectedusers" value="#selectedusers#">
<input type="hidden" name="selectedprojects" value="#selectedprojects#">
<textarea name="comment" rows="3" style="width:450px;font-size:8pt;font-family:arial;"></textarea>
</td>
<td colspan="5" style="border-left:0px;">
Send this note to someone (optional):<br>
<input name="torecipientsbutton" type="button" value="To:" onClick="selectEmails#id#();" style="width:50px;font-size:8pt;">
<input type="text" id="torecipients#id#" name="torecipients#id#" onClick="this.value=''" style="width:380" class="button" value="Hover here for instructions." title="Click the 'To:' button see a team list.&##013;Or click the field to manually enter emails separated by semi-colons.&##013;Leave as-is to post to file only.">
<input type="submit" value="Save" name="submit" style="width:50px;font-size:8pt;">
</form>
This is the javascript code on the parent window:
Code:
function selectEmails#id#()
{
document.getElementById("torecipients#id#").value = '';
window.open("email.selectemails.cfm?formname=statuscomment#id#&fieldname=torecipients#id#&projectid=#projectid#&statusdetailid=#id#&formtype=statusnotes","selectemails#id#","width=550,height=450,left=150,top=200,toolbar=1,status=1,menubar=0;");
}
Here is the portion of form code in the child window that calls the javascript function:
Code:
<form name="selectemails" action="email.selectemails.cfm?projectid=<cfoutput>#url.projectid#</cfoutput>" method="post">
<cfoutput>
<input name="submit" type="button" value="Submit" onClick="post_value('<cfif url.formtype is "issueinsert">issueinsert<cfelseif url.formtype is "reminders">reminders<cfelseif url.formtype is "statusnotes">statusnotes','#url.formname#','#url.fieldname#<cfelse>issuedialogue</cfif>');">
</cfoutput>
<br>
<br>
<div style="overflow:auto;height:320px;">
<table cellpadding="0px" cellspacing="0px" border="1px" bgcolor="#99CCFF" width="517px">
Here is the javascript function in the child window that is posting the selected values in the child form back to the parent form. The form type passed from the parent form is "statusnotes":
Code:
<script langauge="javascript" type="text/javascript">
function post_value(formtype,formname,fieldname)
{
emailvalues=document.forms['selectemails'].selectedemails;
emailvaluescc=document.forms['selectemails'].selectedemailscc;
if (emailvalues != null)
{
txt="";
for (i=0;i<emailvalues.length;++ i)
{
//updateEmailNames(emailvalues[i]);
if (emailvalues[i].checked)
{
txt=txt + emailvalues[i].value + ";";
}
}
if (formtype == "issuedialogue")
{
opener.document.issuedialogue.torecipients.value = txt;
}
if (formtype == "reminders")
{
opener.document.reminders.torecipients.value = txt;
}
if (formtype == "statusnotes")
{
alert(formname + ' ' + fieldname);
opener.document.formname.fieldname.value = txt;
}
else
{
opener.document.issueinsert.torecipients.value = txt;
}
}
if (emailvaluescc != null)
{
txtcc="";
for (i=0;i<emailvaluescc.length;++ i)
{
if (emailvaluescc[i].checked)
{
txtcc=txtcc + emailvaluescc[i].value + ";";
}
}
if (formtype == "issuedialogue")
{
opener.document.issuedialogue.ccrecipients.value = txtcc;
}
if (formtype == "reminders")
{
}
else
{
opener.document.issueinsert.ccrecipients.value = txtcc;
}
}
self.close();
}