Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Array notation help

New Here ,
Dec 04, 2009 Dec 04, 2009

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

370
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 04, 2009 Dec 04, 2009

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

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

Translate
Advocate ,
Dec 04, 2009 Dec 04, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 04, 2009 Dec 04, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 04, 2009 Dec 04, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 04, 2009 Dec 04, 2009
LATEST

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

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources