Skip to main content
July 2, 2009
Question

CF/Ajax - How to pass parameters to a cfwindow?

  • July 2, 2009
  • 2 replies
  • 5418 views

Hi,

Is there a way to pass parameters to a cfwindow?

If yes, please provide me with all relevant details.

HERE IS MY SITUATION:

I have a form, in which I'm looping over a recordset e.g.

<cfform name="frmTest">

     <cfset counter = 0>

     <cfloop query="variables.qTest">

          <cfset counter = variables.counter + 1>

          <cfinput

               type="checkbox"

               name="test_#variables.counter#_ch"

               onClick="showPopUp(#variables.qTest.id#,#variables.qTest.amount#)">

     </cfloop>

</cfform>

Here is my javascript / ajax:

<script type="text/javascript">

<!--

function showPopUp(id,amt){

ColdFusion.Window.show("approvalWindow");

}

//-->

</script>

And here is my cfwindow:

<cfwindow
            name="approvalWindow" center="true" closable="true"
            draggable="false" modal="true" title="Approval"
            initshow="false" width="680" height="315">

HOW CAN I OBTAIN THE VALUES OF id AND amt HERE?

E.g.

<cfset idClicked = id>

<cfset amtClicked = amt>

I'll be needing those 2 variables for further processing...

</cfwindow>

I know I could have used a simple javascript window.open and passed those 2 parameters in the URL scope, but, I don't want my users to see what id I'm sending.

Thanks and regards,

Yogesh Mahadnac.

This topic has been closed for replies.

2 replies

Known Participant
August 19, 2009

I'm not sure why javascript wouldn't work for you? The fact that you are pushing values from a checkboxes is a little different.

Have you looked at this article http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_u-z_3.html ? The bottom examples should help you out with this method.

August 24, 2009

Hi Drew!

Many thanks for your reply.

Quote from my last thread (in reply to Dileep):

"Rest assured, I do know that the JS solution works - this is what I'm currently using - but the aim of this thread was to find out a new type of solution using CF & Ajax."

Thanks and regards,

Yogesh.

Dileep_NR
Inspiring
July 3, 2009

Hi,

Please try this,

<script language="javascript">

    function ShowCfWindow(id,amt)
    {
               
        ColdFusion.Window.create('Window1', 'Window Title','test.cfm?test='+ id,
        {_cf_refreshOnShow:true,x:100,y:100,height:300,width:400,modal:false
            ,closable:true,draggable:true
            ,resizable:true,center:true
            ,initshow:true,minheight:200,minwidth:200 });       
    }
</script>

July 7, 2009

Hi,

Many thanks for your answer.

It actually works under "static" conditions, i.e. if I'm calling the cfwindow inside a cfloop, the value of ID is not refreshed.

Let me show you what I mean.

For example, here is my form

<cfform name="frmTest">

     <cfset counter = 0>

     <cfloop query="variables.qTest">

          <cfset counter = variables.counter + 1>

          <cfinput

               type="checkbox"

               name="test_#variables.counter#_ch"

               onClick="showPopUp(#variables.qTest.id#,#variables.qTest.amount#)">

     </cfloop>

</cfform>

This gives the output, e.g.

Checkbox 1Checkbox 2Checkbox 3Checkbox 4Checkbox 5
ID 1ID 2ID 3ID 4ID 5
showPopUp(1,10)showPopUp(2,15)showPopUp(3,12)showPopUp(4,15)showPopUp(5,50)

Now, here is the showPopUp part (using the solution you provided to me):

<cfajaximport tags="cfwindow">

<script type="text/javascript">
<!--
    function showPopUp(id,amt){
        ColdFusion.Window.create('Window1','Window Title','test.cfm?ID='+ id + '&amt=' + amt,
        {_cf_refreshOnShow:true,height:290,width:630,modal:true,closable:true,draggable:true,resizable:false,center:true,initshow:true});
    }
//-->
</script>

And then on test.cfm, we can easily obtain the value of ID and amt using the url scope

<cfset id = url.ID>

<cfset amt = url.amt>

<cfdump var="#url#" label="Checking values sent from checkbox">

Normally, the value of ID should be 1, 2, 3, 4 or 5 depending on the checkbox you click, right?

When you click the 1st one, ID 1 is sent in the url (this is fine).

However, if you click the 3rd checkbox after having clicked the 1st one, the value of ID and amt still reflect that of the 1st checkbox.

It is not "refreshed" to 3 and 12, you still get ID = 1 and amt = 10.

Is there anything we missed in the showPopUp script?

Thanks and regards,

Yogesh Mahadnac.

August 13, 2009

Hi,

Any help on this issue would be most welcome.

At the moment, I'm only using Javascript window.open and passing the parameters in the URL.

The cfwindow solution would be most appropriate.

Thanks and regards,

Yogesh Mahadnac.