Search code examples
javascriptcoldfusioncfform

javascript-window and cfform


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.


Solution

  • 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.