Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Child Form Values to Parent Form Field

Status
Not open for further replies.

fdgsogc

Vendor
Feb 26, 2004
160
CA
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:
Code:
		<form id="statuscomment#id#" name="statuscomment#id#" method="post" action="projectstatus.cfm" style="margin-bottom:0;">
		Status Meeting Comments:&nbsp;<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();
}
 
Please avoid posting server side code such as cold fusion as it only makes it harder to know what Javascript is actually seeing. Post the rendered HTML source and JS once all server side code has been parsed.

Anyway for your issue, Js will literally look for an element inside the opener's document that has a literal name of "formname" It will not expand the variable when used in the object format. And since since there is no element named "formname" it returns undefined.

When using a variable that holds your form's name use the forms collection array so the variable is used as an index rather than interpreted directly.

opener.document.forms[formname]... same applies with the formfield variable it is noy expanded in the object notation. Use the elements collection array, and use the formfield variable as the index to target.

opener.document.forms[formname].elements[formfield].value

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top