Repeating output with cfif statement

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Repeating output with cfif statement

    I have a problem when multiple checkboxes are "turned on' when multiple values
    exist for a field in a database. For example:

    The following code produces the following output:

    <cfif #INSTREAM_TYPE# IS "Stormwater Outfalls">
    <input type="checkbox" name="INSTREAM_TYPE" value="Stormwater"
    checked>Stormwater Outfalls<br></CFIF>
    <cfif #INSTREAM_TYPE# IS NOT "Stormwater Outfalls">
    <input type="checkbox" name="INSTREAM_TYPE" value="Stormwater">Stormwater
    Outfalls<br>
    </cfif>


    <cfif #INSTREAM_TYPE# IS "Stormwater Detention">
    <input type="checkbox" name="INSTREAM_TYPE" value="WaterDent"
    checked>Stormwater Detention<br></cfif>
    <cfif #INSTREAM_TYPE# IS NOT "Stormwater Detention">
    <input type="checkbox" name="INSTREAM_TYPE" value="WaterDent">Stormwater
    Detention<br>
    </cfif>


    <cfif #INSTREAM_TYPE# IS "Habitat Enhancement and Restoration">
    <input type="checkbox" name="INSTREAM_TYPE" value="Habitat" checked>Habitat
    Enhancement and Restoration<br></cfif>
    <cfif #INSTREAM_TYPE# IS NOT "Habitat Enhancement and Restoration">
    <input type="checkbox" name="INSTREAM_TYPE" value="Habitat">Habitat
    Enhancement and Restoration<br>
    </cfif>



    Stormwater Outfalls
    *Stormwater Detention
    Habitat Enhancement and Restoration

    *Stormwater Outfalls
    Stormwater Detention
    Habitat Enhancement and Restoration

    What I want the output to look like:

    *Stormwater Outfalls
    *Stormwater Detention
    Habitat Enhancement and Restoration

    Any help you could provide would be greatly appreciated

    Thanks






    sviolet Guest

  2. Similar Questions and Discussions

    1. Very odd, page output going into sql statement
      Hi, I have completely failed to come up with an explanation for this one. I have a sql statement near the top of my page. The SQL is...
    2. Help with cfif statement
      Can anyone help me find the correct way to write the following statement? <cfif form.user2 NEQ 15 or 50 or 51 or 52 or 53 or 55 or 200 or 223 or...
    3. CFIF Statement problems
      I am trying to write a cfif statement, which shows a form only if the statemnt acts true. It is a 3 part statement, the first two parts appear to...
    4. Login error with CFIF statement
      Hi all: I'm having trouble with a login CFIF routine. The following code works fine when the login is TRUE, but when I try to login with invalid...
    5. Using cfoutput within a cfif statement
      I am trying to setup a form validation, what i need to do is look at the Specimen Number entered and compare it against the database to see if it...
  3. #2

    Default Re: Repeating output with cfif statement

    this will reduce the amount of code


    <input type="checkbox" name="INSTREAM_TYPE" value="Stormwater" <cfif
    #INSTREAM_TYPE# IS "Stormwater Outfalls">checked</CFIF>>Stormwater Outfalls<br>
    <input type="checkbox" name="INSTREAM_TYPE" value="WaterDent" <cfif
    #INSTREAM_TYPE# IS "Stormwater Detention">checked</cfif>>Stormwater
    Detention<br>
    <input type="checkbox" name="INSTREAM_TYPE" value="Habitat" <cfif
    #INSTREAM_TYPE# IS "Habitat Enhancement and Restoration">checked</cfif>>Habitat
    Enhancement and Restoration<br>

    jorgepino Guest

  4. #3

    Default Re: Repeating output with cfif statement

    Do you have this code within a loop?.

    Also you could combine two cfifs into one by doing this

    <input type="checkbox" name="INSTREAM_TYPE" value="Stormwater" <cfif
    instream_type eq "Stormwater Outfalls">checked</cfif>>Stormwater
    Outfalls<br></CFIF>

    CFDEBUG Guest

  5. #4

    Default Re: Repeating output with cfif statement

    Thanks for your help

    The following works except for the fact that if a checkbox is not selected -
    the checkbox label doesn't show up. How can i make it so a checkbox appears
    with a label but is unchecked if the the value doesn't exist? (note: different
    variable names in this post)

    <input type="checkbox" name="INSTREAM_TYPE" value="Sediment Removal" <cfif
    #instream_type# eq "Sediment Removal">checked
    <br>Sediment Removal</cfif>

    <input type="checkbox" name="INSTREAM_TYPE" value="Vegetation Removal" <cfif
    #instream_type# eq "Vegetation Removal">checked
    <br>Vegetation Removal</cfif>

    <input type="checkbox" name="INSTREAM_TYPE" value="Debris Removal" <cfif
    #instream_type# eq "Debris Removal">checked
    Debris Removal<br></cfif>

    sviolet Guest

  6. #5

    Default Re: Repeating output with cfif statement

    I should mention, I am not using a cfloop, just cfoutput:

    <CFOUTPUT QUERY="EditQuery2">
    <input type="checkbox" name="INSTREAM_TYPE" value="Sediment Removal" <cfif
    #instream_type# eq "Sediment Removal">checked
    <br>Sediment Removal</cfif>

    <input type="checkbox" name="INSTREAM_TYPE" value="Vegetation Removal" <cfif
    #instream_type# eq "Vegetation Removal">checked
    <br>Vegetation Removal</cfif>

    <input type="checkbox" name="INSTREAM_TYPE" value="Debris Removal" <cfif
    #instream_type# eq "Debris Removal">checked
    Debris Removal<br></cfif>

    </CFOUTPUT>

    sviolet Guest

  7. #6

    Default Re: Repeating output with cfif statement

    Well, you have same variable names. Anyway you need to put the cfif before the
    label like this

    <input type="checkbox" name="INSTREAM_TYPE" value="Sediment Removal" <cfif
    instream_type eq "Sediment Removal">checked</cfif>>
    <br>Sediment Removal.

    Since you are using query, ofcourse it will show up multiple times since it
    loops thru all rows and displays checkboxes that many times. To remove that, do
    this

    <cfoutput>
    <cfset instr_list = valuelist(EditQuery2.instream_type)>
    <input type="checkbox" name="INSTREAM_TYPE" value="Sediment Removal" <cfif
    listfindnocase(instr_list,"Sediment Removal")>checked</cfif>
    <br>Sediment Removal

    Do the other 2 checkboxes similar to above. If this has any issue, you could
    use quotedvaluelist() instead of valuelist() since this is a string. But I'm
    sure valuelist() itself should work.

    CFDEBUG Guest

  8. #7

    Default Re: Repeating output with cfif statement


    Well, you have same variable names. >>>Sorry my mistake! Anyway you need to
    put the cfif before the label like this

    <input type="checkbox" name="INSTREAM_TYPE" value="Sediment Removal" <cfif
    instream_type eq "Sediment Removal">checked</cfif>>
    <br>Sediment Removal.

    Since you are using query, ofcourse it will show up multiple times since it
    loops thru all rows and displays checkboxes that many times. To remove that, do
    this

    <cfoutput>
    <cfset instr_list = valuelist(EditQuery2.instream_type)>
    <input type="checkbox" name="INSTREAM_TYPE" value="Sediment Removal" <cfif
    listfindnocase(instr_list,"Sediment Removal")>checked</cfif>
    <br>Sediment Removal


    >>>>I tried the above and still the checkbox repeats (if there are 3 instream
    type values, the checkbox repeats 3 times)
    ???Thanks of your help

    sviolet Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139