7 Replies Latest reply on Aug 24, 2009 2:28 AM by YogeshM

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

    YogeshM Level 1

      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.

        • 1. Re: CF/Ajax - How to pass parameters to a cfwindow?
          Dileep_NR Level 2

          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>

          1 person found this helpful
          • 2. Re: CF/Ajax - How to pass parameters to a cfwindow?
            YogeshM Level 1

            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,resi zable: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.

            • 3. Re: CF/Ajax - How to pass parameters to a cfwindow?
              YogeshM Level 1

              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.

              • 4. Re: CF/Ajax - How to pass parameters to a cfwindow?
                Dileep_NR Level 2

                try this

                 

                <script language="javascript">
                function viewPopUp(idVal)
                {

                myWindow=window.open('file2.cfm?id='+idVal,'file2','width=400,height=400')

                 

                }
                </script>

                • 5. Re: CF/Ajax - How to pass parameters to a cfwindow?
                  YogeshM Level 1

                  Hi,

                   

                  Many thanks for your answer.

                   

                  However, I'm currently looking for the cfwindow answer, not the Javascript solution.

                   

                  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.

                   

                  If you refer to the explanations I've given in the thread, at the moment, when using the cfwindow, the values are not refreshing.

                   

                  Normally, inside the loop, the values are dynamic - 1, 2, 3, 4, 5, etc.

                   

                  If I click on the 1st checkbox, the value should be 1, 2nd checkbox - value 2, etc.

                   

                  With the cfwindow, if I click on the 1st checkbox, the value on the window that pops-up is 1 - fine.

                   

                  Now, if you click on the 2nd checkbox AFTER you have clicked on the 1st one, the value on the popup window is STILL 1, not 2.

                   

                  It is because of this problem that I've posted this thread.

                   

                  You may try out the example that I've given in the thread to help you understand.

                   

                  Hope it's clearer so that you may better assess the situation and provide a possible solution.

                   

                  Thanks and regards,

                   

                  Yogesh

                  • 6. Re: CF/Ajax - How to pass parameters to a cfwindow?
                    drew_lw Level 1

                    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.

                    • 7. Re: CF/Ajax - How to pass parameters to a cfwindow?
                      YogeshM Level 1

                      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.