Skip to main content
Gear_Head
Known Participant
March 21, 2019
Question

Coma at the end of each eanswer of my checkbox

  • March 21, 2019
  • 1 reply
  • 291 views

I have a simple query for a list using checkbox :

<cfloop query="getlist">

#thingstodo# : <input type="checkbox" name="thingstodo" value="<br/>#thingstodo#"> <p>

</cfloop>

So it will apear like this :

Some list of things to do 1 : <input type="checkbox" name="thingstodo" value="<br/>Some list of things to do 1"> <p>

Some list of things to do 2 : <input type="checkbox" name="thingstodo" value="<br/>Some list of things to do 2"> <p>

Some list of things to do 3 : <input type="checkbox" name="thingstodo" value="<br/>Some list of things to do 3"> <p>

Some list of things to do 4 : <input type="checkbox" name="thingstodo" value="<br/>Some list of things to do 4"> <p>

My problem is it adds a coma at the end and this is how it looks in the database :

<br/>Some list of things to do 1,<br/>

Some list of things to do 2,<br/>

Some list of things to do 3,<br/>

Some list of things to do 4,<br/>

Some list of things to do 5,<br/>

I tryed using replace before i send it in the databse but i think i'm doing it wrong plus some of the text in the list might have a coma in it so this might not be the answer:

<cfset thingstodo = Replace(thingstodo, ",","","ALL")>

Thanks for your help

    This topic has been closed for replies.

    1 reply

    WolfShade
    Legend
    March 21, 2019

    When you have a few checkboxes with the same name, depending upon which version of CF you are using the form submits those checkbox values as either a comma-delimited list or an array.  Apparently you're using an older version of CF that submits the values as a comma-delimited list.

    If any of the values contain a comma, this will make things extremely difficult as anything that works with lists will detect every comma as a delimiter.  The option to avoid this is to use an HTML entity to represent commas in the value, allowing the comma to still appear in a browser but will not screw up the list.  Then, join the values replacing the delimiting comma with a line break <br />.

    V/r,

    ^ _ ^