Skip to main content
Participating Frequently
December 4, 2009
Answered

Array notation help

  • December 4, 2009
  • 2 replies
  • 429 views

Hopefully this is a straightforward one for somebody!

I've got a form that has a looped section. I'm currently trying to display this on the action page.

This works

#form["add" & i & "Desc"]#

as it should.

I've also got another section where I'm processing the date then want to display it as below:

#dateFormat("# add#i#bookingDate #", "yyyy-mm-dd")#     (spacing added for clarity)

which obviously doesn't work. I want to format the date as shown using date add#i#bookingDate. This section is in a loop, index i.

I'm guessing I need to change this to something like the working example above but what do I replace form with? can I just put

<h1># ["add" & i & "bookingDate"] #</h1>

Thanks

Michael

    This topic has been closed for replies.
    Correct answer Dan_Bracuk

    You can use any scope with array notation, including the variables scope.  You would output:

    #Dateformat(variables["add" & j & "bookingdate"], "mask")#

    2 replies

    Inspiring
    December 4, 2009

    You have the right idea.  However, to answer your question, I need to know where add come from.  Is it a formfield?

    Participating Frequently
    December 4, 2009

    Apologies for the pseudo code but i'm on a different machine now.

    <form>

       <cfset x = "3"><input name=x value = #x#>

      <cfloop from "1" to "x" step 1 index i>

         <select name add#i#bookDay><option value=1>1st</><option value =2>2nd</>etc.</select>

         <select name add#i#bookMonth><option value=2009-10>October</><option value =2009-11>November</>etc.</select>

      </cfloop

    </form>

    action page

    ----------------

    <cfloop from 1 to #form.x# step 1 index j>

        do stuff to check dates are valid

      

    <cfset "add#j#bookingDate" = createDate(mid("#form["add" & j & "bookMonth"]#", 3, 2), mid("#form["add" & j & "bookMonth"]#", 6, 2), "#form["add" & j & "bookDay"]#")>
    </cfloop>

    do other stuff

    <cfoutput>

    <cfloop from 1 to #form.x# step 1 index k>

           <h1>month: #form["add" & k & "bookMonth"]#</h1> <!---- displays correctly straight from submitted form --->

         <h3>full date: add#k#bookingDate</h3> <!--- taken from the cfset above - if i display #add3bookingDate# then it works but I can't add extra #'s at the beginning or end or the value of k stops working. Can I use array notation - what do i use instead of form? Of should I be creating a structure instead of cfset above? --->

    </cfloop>

    </cfoutput>

    </cfloop

    Dan_BracukCorrect answer
    Inspiring
    December 4, 2009

    You can use any scope with array notation, including the variables scope.  You would output:

    #Dateformat(variables["add" & j & "bookingdate"], "mask")#

    Inspiring
    December 4, 2009

    Use the "Evaluate" function

    http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000945.htm

    HTH