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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undefined Passing Form Value from Child to Parent

Status
Not open for further replies.

ejrhodes

MIS
Jul 9, 2001
20
US
Hey everyone, I am sure this is a simple one, but I am curious if someone can help me debug why I am getting an undefined value when passing a value from the child window to the parent window.

On my child window, I have the following code
Code:

<form name="selectrfc" action="">
<tr> <td align="center"> <input name="rfcid" type="radio" value="2"> </tr>

<tr> <td align="center"> <input name="rfcid" type="radio" value="1"> </tr>
<tr><td><input type=button value=' close window ' onClick='javascript:window.opener.document.view_this_pm_form.rfc.value=document.selectrfc.rfcid.valu e;window.close();'></td></tr>
</form>



On my parent window, i have a text field called rfc. When I click the submit button on my child window, the text box on the parent window gets updated to "undefined." What I want to pass is the value of the radio that is selected. Any thoughts?
 
you have two form elements with the same name. you will need to reference them using an array notation.

Code:
<input type=button 
       value=' close window '
       onClick='opener.document.view_this_pm_form.rfc.value=document.selectrfc.rfcid[red][0][/red].valu e;window.close();'>

where 0 is the first field and 1 is the second.

also, your form should encapsulate your entire table. no tags are meant to be between the form tag and the tr tag.



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
This is where I am confused, how would I modify my form such that I can only send the value selected to the form. I see the problem wiht my current form design
 
sorry, i didn't pay attention. the radio buttons are ok as-is. since you're using javascript, i'd write a function:

Code:
function doThing(f) {
    var r = f.elements['rfcid'];
    var v = "";
    for ( var i = 0; i < r.length; i++ ) {
        if (r[i].checked) v = r[i].value;
    }
    if ( v != "" ) {
        opener.document.view_this_pm_form.rfc.value = v;
        window.close();
    } else {
        alert('please select a radio button');
    }
}

and then call the function from your form:

Code:
<input type=button value=' close window ' onClick='doThing();' />



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I finally was able to attempt this function and I am getting an error that I do not understand.

The form HTML is as follows;
Code:
<html>
<head>
<title>Modify RFC for site 0095 </title>
<LINK REL="stylesheet" TYPE="text/css" HREF="generic.css">
<script language="JavaScript" src="utils.js"></script>
<script language="Javascript" src="date-picker.js"></script>
<script language=javascript>
function doThing(f) {
    var r = f.elements['rfcid'];
    var v = "";
    for ( var i = 0; i < r.length; i++ ) {
        if (r[i].checked) v = r[i].value;
    }
    if ( v != "" ) {
        window.opener.document.myDiv.innerHTML = v;
        window.close();
    } else {
        alert('please select a radio button');
    }
}

</script>
</head>
<body topmargin="0" text="#000000" link="#00FFFF" vlink="#00FFFF" alink="#00FFFF" Onload="TimeIt();">


<br>
<font size="2" type="arial"> If an RFC is not created, a PM Form can not be entered for this location. </font>
<br><br>


<table border=1 bordercolor=#C2D5FC cellspacing=0 cellpadding=5>
<tr><td colspan=6 align=center  bgcolor=#C2D5FC><font size=3><b> RFC Data for Site Number: 0095</b></font>&nbsp;---<a href="pm_rfc.asp?sitenumber=0095&action=edit"> Edit </a></td></tr>

<tr><td width="1%"><td align="center"><b>RFC Number</b></td><td align="center"><b>Work Order Number</b></td><td align="center"><b>Start Date</b></td><td align="center"><b>End Date</b></td><td align="center"><b>Status</b></td></tr>




<form name="selectrfc" action="">
<tr>
<td align="center">
<input name="rfcid" type="radio" value="7">
<input name="rfcselected" type="hidden" value="122333">
<td align="center">122333
<td align="center">1111111111
<td align="center">7/4/2006 
<td align="center">7/24/2006
<td align="center"> New 
</tr>
<tr>
<td align="center">
<input name="rfcid" type="radio" value="3">
<input name="rfcselected" type="hidden" value="123344">
<td align="center">123344
<td align="center">1111111111
<td align="center">6/29/2006 
<td align="center">6/30/2006
<td align="center"> New 
</tr>
<tr>
<td align="center">
<input name="rfcid" type="radio" value="2">
<input name="rfcselected" type="hidden" value="121222">
<td align="center">121222
<td align="center">1212211121
<td align="center">6/26/2006 
<td align="center">6/28/2006
<td align="center"> New 
</tr>
<tr>
<td align="center">
<input name="rfcid" type="radio" value="0">
<input name="rfcselected" type="hidden" value="None currently selected">
<td align="left" colspan="6">None selected, no questions will be accepted for this work
</tr>
<tr><td><input type=button value=' close window ' onClick='doThing();'></td></tr>
</form>

I am following your function and it makes sense, but the errror I get is: 'elements is null or not an object.' Any ideas on what I am doing wrong? Thanks
 
So I got the function to work by referencing the actual form elements.

Code:
function doThing() {
    var r = document.selectrfc.rfcid
    var g = document.selectrfc.rfcselected
    var v = "";
    var w= "";
    for ( var i = 0; i < r.length; i++ ) 
    {
        if (r[i].checked) 
        {
	        v = r[i].value;
	        w=g[i].value;
        }
    }
    if ( v != "" ) {
        window.opener.myDiv.innerHTML = "RFC Selected: " + w;
        window.opener.document.view_this_pm_form.rfcid.value= v;
        window.close();
    } 
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top