Skip to main content
Participant
May 5, 2008
Question

CFM Forms and cfoutput

  • May 5, 2008
  • 3 replies
  • 344 views
I have a form with a list of checkbox inputs. Each checkbox uses the same name, but different values. The idea is that the user can click any combination of the checkboxes and that will output through to page 2. However, when I get to page 2 the values of the checked boxes are listed in a row deliminated by commas. I would like the valuse to show up in a list deliminated by a line break.

So for example my form would look like this:
input type=checkbox name=item value=item1
input type=checkbox name=item value=item2
input type=checkbox name=item value=item3

What I would like is for the action page to display whichever items were checked like this:
item1
item2
item3

I currently am trying:
<cfoutput>
#form.item#
</cfoutput>
but that is just displaying them like this:
item1, item2, item3

I don't want the items that were not checked on page 1 to list on page 2.

Any idea?

    This topic has been closed for replies.

    3 replies

    Inspiring
    May 5, 2008
    quote:

    Originally posted by: scuba7
    I have a form with a list of checkbox inputs. Each checkbox uses the same name, but different values. The idea is that the user can click any combination of the checkboxes and that will output through to page 2. However, when I get to page 2 the values of the checked boxes are listed in a row deliminated by commas. I would like the valuse to show up in a list deliminated by a line break.

    So for example my form would look like this:
    input type=checkbox name=item value=item1
    input type=checkbox name=item value=item2
    input type=checkbox name=item value=item3

    What I would like is for the action page to display whichever items were checked like this:
    item1
    item2
    item3

    I currently am trying:
    <cfoutput>
    #form.item#
    </cfoutput>
    but that is just displaying them like this:
    item1, item2, item3

    I don't want the items that were not checked on page 1 to list on page 2.

    Any idea?



    There are lots of ways to accomplish this. The simplest is to use the Cold Fusion replace function to replace the commas with a break tag.

    Whatever method you choose, make sure that you submit your form without checking any of the boxes during development and testing.
    Inspiring
    May 5, 2008
    When you use checkboxes in your form with a shared name value (item in your case), the values are passed in as a comma-delimited string. One option (and there are many) is to convert the list to an array and then just loop over your array.

    For example:
    <cfscript>
    myList = form.item;
    myArrayList = ListToArray(myList);
    </cfscript>
    <cfloop from="1" to="#ArrayLen(myArrayList)#" index="i">
    <cfoutput>#myArrayList #</cfoutput><br/>
    </cfloop>

    There are probably better ways to do this but this will get the job done and get you started.

    Cheers,
    Craig

    Inspiring
    May 5, 2008
    Maybe look into using a <cfloop> over a list?

    scuba7 wrote:
    > I have a form with a list of checkbox inputs. Each checkbox uses the same name,
    > but different values. The idea is that the user can click any combination of
    > the checkboxes and that will output through to page 2. However, when I get to
    > page 2 the values of the checked boxes are listed in a row deliminated by
    > commas. I would like the valuse to show up in a list deliminated by a line
    > break.
    >
    > So for example my form would look like this:
    > input type=checkbox name=item value=item1
    > input type=checkbox name=item value=item2
    > input type=checkbox name=item value=item3
    >
    > What I would like is for the action page to display whichever items were
    > checked like this:
    > item1
    > item2
    > item3
    >
    > I currently am trying:
    > <cfoutput>
    > #form.item#
    > </cfoutput>
    > but that is just displaying them like this:
    > item1, item2, item3
    >
    > I don't want the items that were not checked on page 1 to list on page 2.
    >
    > Any idea?
    >
    >
    >