• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1337
  • Last Modified:

Passing Data From A Pop-Up Window To A Parent Window Using ColdFusion And Javascript

I have calling the popup from where I do UPdate the dataabse. WHen the update is happened I want the parent page change it value (check box checked/unchecked)
The code is below
Parent page 
<script language="Javascript">
	//function updateAcceptance (Employeeid) {
	//window.open("test.cfm?EmpID="+ Employeeid, 'PrintWin', 'toolbar=yes, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, width=500, height=400');
		
		//}
 
function PopUp(Employeeid){
 
// Open the new window with ID selector.
// Pass PopUpHandler() as the data handler
// to which the popup will broadcast its'
// data selection.
window.open("test.cfm?EmpID="+ Employeeid, 'PrintWin', 'toolbar=yes, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, width=500, height=400');
void( 0 );
}
</script>
<cfform name="frm" method="post" action="" id="frm">
							<cfif getCapstone.recordcount gt 0>
								<input type="checkbox" name="chk" id="chk" value="#getCapstone.isAccept#" onClick="javascript:PopUp (#Employeeid#);" <cfif getCapstone.isAccept eq 1>checked</cfif>>
								<cfelse>
									<input type="checkbox" name="chk" id="chk" disabled>
								</cfif>
							</cfform>
 
---PopUp---
<script type="text/javascript">
<cfif Len(url.EMpID)>
 
function SendData( objForm ){
var strIDs = "";
var i = 0;
 
// Loop over the form fields to build the data.
for (i = 0 ; i < objForm.chk.length ; i++){
 
if (objForm.chk[ i ].checked){
 
strIDs = (
strIDs +
(strIDs.length > 0 ? "," : "") +
objForm.chk[ i ].value
);
 
}
 
}
 
 
// Try to pass the data back to caller.
try {
 
<cfoutput>
window.opener.#url.EMpID#( strIDs );
</cfoutput>
 
 
// Close current window.
window.close();
 
} catch (objError){
 
alert(
"There was an error passing the\n" +
"data back to the parent window"
);
 
}
 
}
 
<cfelse>
 
<!---
We have no data handler. Alert the user
before they do anything.
--->
alert(
"Something went wrong. No data handler\n" +
"can be found. Please try closing and\n" +
"opening this window again"
);
 
</cfif>
 
		</script>
<cfform name="frm">
		<input	type="hidden"	name="EMpID"	value="#url.EmpID#"/>
				<h2 align="center">Accept Capstone</h2>
					<div align="center">
			Do Not Accept	<cfinput type="radio" id="chk" name="chk" value="0" checked="#IIF(qryGetCapstone.isAccept eq 0, DE('Yes'), DE('No'))#" >&nbsp;&nbsp;&nbsp;&nbsp;
			Accept<cfinput type="radio" name="chk"  id="chk" value="1" checked="#IIF(qryGetCapstone.isAccept eq 1, DE('Yes'), DE('No'))#" >
			<br />
			<cfinput type="submit" name="btnSubmit" id="btnSubmit" value="Submit" onclick="SendData(this.form );">
			
			</div>
		</cfform>

Open in new window

0
erikTsomik
Asked:
erikTsomik
  • 2
  • 2
1 Solution
 
black0psCommented:
First, what I think you are trying to do it what Ajax will do. When you click the radio button, it updates the database. You don't need a popup window to make this happen. If you use a popup window, some browsers will block this popup and the update won't take place. Look into using cfajax.
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
OK. I rewrote the event now i am suing the AJAX but i do not get dataabse updated
<script type="text/javascript">
      function makeRequestAll(url,parameters)
{
var httpRequest=null;
var mode=true;//default to ASYNCHRONOUS
if(arguments.length==3)
{
mode=(arguments[2]==true);
}


if (window.XMLHttpRequest)// Mozilla, Safari, ...

    {
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType )
        {
           // httpRequest.overrideMimeType('text/xml');
            // See note below about this line
        }
    }
    else if (window.ActiveXObject)// IE
    {
        try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try {
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {}
        }
    }

    if (!httpRequest)
    {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }

    httpRequest.onreadystatechange = function(){
        if(httpRequest.readyState==4)
            reportResutlsAll(httpRequest.responseText);

    };
//alert(parameters);
    if(parameters)//POST request
    {

        httpRequest.open('POST', url, mode);
        httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        httpRequest.setRequestHeader("Content-length", parameters.length);
        httpRequest.setRequestHeader("Connection", "close");
        httpRequest.send(parameters);
      
    }
    else//GET request
    {
        httpRequest.open('GET', url, mode);
             httpRequest.send('');
      
    }
       
}


 function reportResutlsAll(strResult)
{
 
      document.getElementById('chk').checked ==true;
      
}
            


function preprocessAll2(obj)
{
        switch(obj.id)
    {
                   case "chk":
                   var poststr="";
                    poststr += obj.id + "=" + encodeURI(obj.value);
                  poststr += "&";
                  poststr += "chk=" + encodeURI(document.getElementById("chk").value);
                  alert (poststr);
                  makeRequestAll('test.cfm', poststr);
             
            
            }
}
      </script>
form
<form name="frm" method="post" action="" id="frm">
                                          <cfif getCapstone.recordcount gt 0>
                                                <input type="checkbox" name="chk" id="chk" value="#getCapstone.isAccept#" onClick="javascript:preprocessAll2 (this);" <cfif getCapstone.isAccept eq 1>checked</cfif>>
                                                <cfelse>
                                                      <input type="checkbox" name="chk" id="chk" disabled>
                                                </cfif>
                                          </form>

Back END
 <cfquery name="qryUpdate" >
                              Update EDITCapstone set isAccept = <cfif  chk eq 1>0<cfelse>1</cfif>,acceptedBy = #session.EmpID#  where EmpID = #url.EmpID#
            </cfquery>
0
 
fsze88Commented:
try to place
window.opener.document.frm.chk.checked=false somewhere in popup window's javascript....
more reference
http://www.w3schools.com/HTMLDOM/prop_checkbox_checked.asp
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
fsze88: Nope still does not work. It updates the dataabse but does not change the checkbox
0
 
fsze88Commented:
erikTsomik,

please try sample example

http://www.kennam.com/experts-exchange.com/24131312.html#
I really want to help you to solve your problem!
parent
<form name="form1">
 
<input type="checkbox" name="cb">
</form>
 
<a href="#" onclick="window.open('24131312pop.html')">open popup</a>
 
 
popup
<form name="popupform1">
 
<input type="checkbox" name="popupform1cb" onclick="window.opener.document.form1.cb.checked=this.checked">
</form>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now