views:

43

answers:

1

I have Parent page and a Child page('empW.cfm'),which is nothing but a popup window on one of the form fields on Parent page. I am using <cfform> in the Parent page. I want to populate the data from this Child-page-popup-window, to that related form field in Parent -page. Tried all means but no success till now.

Parent page:-

<script type="text/javascript" src="test.js" >

    function doSubmit() {
      var Emp = document.getElementById("emp");
      var getName = document.getElementById("getName");
      Emp.value = getName.value;
                }
           </script> 
</head>
<body>
<cfajaximport tags="cfform,cfwindow">
<cfform action="Action.cfm" name="formE" id="formE" preserveData="true"  enctype="multipart/form-data" method="post" onsubmit="return validate(document.formE);"  >  
 <table >
    <tbody>    
            <tr><td  > Name*: </td><td><cfinput name="Name" id="Name"  type="text"  ></td></tr>          

             <tr><td > EMP:</td>

     <td><input name="searchName" id="emp"   onClick="createWindow('empW.cfm')"></td>
    </tr>  
   </tbody>
 </table>
</cfform>

Child/Window page:-

<!--- empW.cfm --->
<cfform name="formI" id="formI" preserveData="false" method="post">
 <table>
 <tr><td>
  <cfif isdefined('form.getName')>
   <cfoutput>Selected = #form.getName#!</cfoutput>
  <cfelse>
   Selected =
  </cfif>
 </td></tr>
 <tr>
  <input name="getName" id="getName" type="text" value="Find emp name" >
  <input name="Add" id="getName" type="submit" onChange="doSubmit();">
 </td></tr>
 </table>
</cfform>

Please help.

+3  A: 

Your main page code:

<td><input name="searchName" id="emp" onclick="ColdFusion.Window.create('w1','Title','empW.cfm')"></td>

empW.cfm page code:

<input name="Add" id="getName" type="button" value="submit" onclick="document.getElementById('emp').value=document.getElementById('getName').value;">

Also remove src attribute from parent page's script code.

In empW.cfm page, submit button's onChange() will be never called as submit() event will be called first and therefore you lost onChange() event.

Vikas
Thanks Vikas! But was wondering what is the need of "W1" and "Title"
Fransis
in main page code...Onclick="document... ('w1','Title','empW.cfm')"
Fransis
See the syntax here: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WS0ef8c004658c1089-6262c847120f1a3b244-7fbf.html
Vikas
I am using CF8 anyhow it worked.Thanks a lot
Fransis
w1 represents the unique identifer for that window, title is the displayed in the cfwindow in the top-left, I have put icons in the title area to make it look nice. the last parameter is the actual template being called, and can pass parameters with it.
cfEngineers
when i followed Vikas suggestion <input name="Add" id="getName" type="button" value="submit" onclick="document.getElementById('emp').value=document.getElementById('getName')."> is working but...
Fransis
am able to pass only the first value from the given results of #form.getName#!.
Fransis
i mean from a list of 10 results only the first result is being passed
Fransis
even if other results are selected
Fransis
You can use jquery, `$('#getName option:selected').text();`
Vikas