Skip to main content
November 22, 2010
Question

cfif and blank space showing

  • November 22, 2010
  • 4 replies
  • 780 views

Hi, I have a form with several form fields that may or may not have data entered in. This form is used to build new html pages. If a certain form doesn't have data entered, I need this place in the template to be blank. I used a cfif statement

<cfif SESSION.itemWatts NEQ "">Watts: <cfoutput>#SESSION.itemWatts#</cfoutput> </cfif>

Which works very well. However, it still leaves a blank "space" that the Watts line WOULD have taken up. There are about 8 different formfields here in a row that potentially would leave a big gap in the page. Is there a way to "collapse this area when no data is entered? There was a <p> tag around this area, but I removed them and still get the space. If you need any more code, then let me know.

Thanks for any help!

    This topic has been closed for replies.

    4 replies

    November 22, 2010

    Resolved

    November 22, 2010

    Thanks guys! I figured it out. I had the <p> tag around all my cfif statements. I went and added

    a <p> tag around each one separately and it works great now.

       <cfif SESSION.itemWatts NEQ ""><p class="watts">Watts: <cfoutput>#SESSION.itemWatts#</cfoutput></p></cfif>
       <cfif SESSION.itemVolts NEQ ""><p class="volts">Volts: <cfoutput>#SESSION.itemVolts#</cfoutput></p></cfif>
       <cfif SESSION.itemGlass NEQ ""><p class="glass">Glass: <cfoutput>#SESSION.itemGlass#</cfoutput></p></cfif>
       <cfif SESSION.itemBase NEQ ""><p class="base">Base: <cfoutput>#SESSION.itemBase#</cfoutput></p></cfif>

    Thanks again!

    Participating Frequently
    November 22, 2010

    It looks like some process is setting session vars between the form

    submission and this output, so I would check on that.

    More simply, you could just test the form scope itself:

    </cfif

    Inspiring
    November 22, 2010

    Use

    <table>

         <cfif isdefined('SESSION.itemWatts') and len(trim(#SESSION.itemWatts#)) gt 0>

              <tr>

                   <td>Watts :</td>

                   <td><cfoutput>#SESSION.itemWatts#</cfoutput></td>

              </tr>

         </cfif>

         <cfif isdefined('SESSION.Field2') and len(trim(#SESSION.Field2#)) gt 0>

              <tr>

                   <td>Field2 :</td>

                   <td><cfoutput>#SESSION.Field2#</cfoutput></td>

              </tr>

         </cfif>

         and field3, field4 so on..

    </table>

    HTH