Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2009-02-10
5
Medium Priority
?
1,309 Views
Last Modified: 2013-12-24
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
Comment
Question by:erikTsomik
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:black0ps
ID: 23606723
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
 
LVL 19

Author Comment

by:erikTsomik
ID: 23608246
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
 
LVL 15

Accepted Solution

by:
fsze88 earned 1500 total points
ID: 23608802
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
 
LVL 19

Author Comment

by:erikTsomik
ID: 23608906
fsze88: Nope still does not work. It updates the dataabse but does not change the checkbox
0
 
LVL 15

Expert Comment

by:fsze88
ID: 23629499
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
What You Need to Know when Searching for a Webhost Provider
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question