10 Replies Latest reply on Dec 3, 2012 10:19 PM by BKBK

    CFELSE not executing

    NatheManning Newcomer

      I have a form with simple IF (field not blank) output field ELSE output   structures.  In the middle of processing them, ColdFusion starts skipping the CFELSE parts of these structures.

       

      ColdFusion 10.

       

      I don't see anything wrong with the code.

       

      Anybody know what's going on?

       

      Nathan Manning

        • 1. Re: CFELSE not executing
          Dan Bracuk Rockstar

          My guess is white space.

           

          I tend to approach problems like this with this sort of thing.

           

          if some condition is true

          output "yes"

           

          else

          output "no"

          output other relevent data to help you figure out why you are in the else block.

          • 2. Re: CFELSE not executing
            NatheManning Newcomer

            The test is <CFIF queryfield NEQ ""> <CFELSE>.  I am in the process of adding cfparameters defaulted to "" for the query result parameters to see if that helps...

            • 3. Re: CFELSE not executing
              12Robots Champion

              I will buy you a pony if you stop capitalizing your tags.

               

              Jason

              • 4. Re: CFELSE not executing
                Dan Bracuk Rockstar

                Still looks like white space.  It also looks like you might want to output some data into your if block to see what's going on.  Maybe something like "before__" & "___after"

                • 5. Re: CFELSE not executing
                  NatheManning Newcomer

                    <table width="60%" border="1" align="center" cellpadding="5" cellspacing="5">
                      <tr>
                        <th>Row</th>
                     <th>Primary MD ID</th>
                        <th>Primary MD<br>Last Name</th>
                        <th>Primary MD<br>First Name</th>
                        <th>Primary MD<br>Middle Name</th>
                     <th>Address<br/>Line 1</th>
                     <th>Address<br/>Line 2</th>
                     <th>City</th>
                     <th>State</th>
                     <th>Zip Code</th>
                     <th>Phone Number</th>
                     <th>Email Address</th>
                      </tr>
                      <cfoutput query="SelectPrimaryInfo">
                       <tr>
                         <td align="center">#CurrentRow#</td>
                         <td align="center">#PrimaryID#</td>
                         <td>#PLName#</td>
                         <td>#PFName#</td>
                      <cfif PMName NEQ "">
                       <td>#PMName#</td>
                      <cfelse>
                       <td> </td>
                      </cfif>
                     
                      <cfif Address1 NEQ "">
                       <td>#Address1#</td>
                      <cfelse>
                       <td>Not Provided</td>
                      </cfif>
                     
                      <cfif Address2 NEQ "">
                       <td>#Address2#</td>
                      <cfelse>
                       <td>Not Provided</td>
                      </cfif>
                     
                      <cfif City NEQ "">
                       <td>#City#</td>
                      <cfelse>
                       <td>Not Provided</td>
                      </cfif>
                     
                      <cfif State NEQ "">
                       <td>#SelectState.StateName#</td>
                      <cfelse>
                       <td>Not Provided</td>
                      </cfif>

                   

                      <cfif Phone NEQ "">
                       <td>#Phone#</td>
                      <cfelse>
                       <td>Not Provided</td>
                      </cfif>

                   

                      <cfif Email NEQ "">
                       <td><a href="#Email#mailto:#Email#">#Email#</a></td>
                      <cfelse>
                       <td>Not Provided</td>
                      </cfif>
                       </tr>
                      </cfoutput>
                    </table>

                   

                  The <cfif Phone NEQ ""> is where the <cfelse> gets skipped.

                  • 6. Re: CFELSE not executing
                    WolfShade Champion

                    Put all of it into a cftry/cfcatch, then cfdump the #cfcatch#.

                     

                    ^_^

                    • 7. Re: CFELSE not executing
                      meensi Helper

                      Hi,

                      You can try the below.

                       

                      <cfif Len(Phone) NEQ 0>

                           <td>#Phone#</td>

                          <cfelse>

                           <td>Not Provided</td>

                          </cfif>

                      • 8. Re: CFELSE not executing
                        BKBK Rockstar

                        Trim.

                         

                        <cfif trim(Address1) NEQ "">

                        <td>#Address1#</td>

                        <cfelse>

                        <td>Not Provided</td>

                        </cfif>

                         

                        <cfif trim(Address2) NEQ "">

                        <td>#Address2#</td>

                        <cfelse>

                        <td>Not Provided</td>

                        </cfif>

                         

                        <cfif trim(City) NEQ "">

                        <td>#City#</td>

                        <cfelse>

                        <td>Not Provided</td>

                        </cfif>

                         

                        <cfif trim(State) NEQ "">

                        <td>#SelectState.StateName#</td>

                        <cfelse>

                        <td>Not Provided</td>

                        </cfif>

                         

                        <cfif trim(Phone) NEQ "">

                        <td>#Phone#</td>

                        <cfelse>

                        <td>Not Provided</td>

                        </cfif>

                         

                        <cfif trim(Email) NEQ "">

                        <td><a href="#Email#mailto:#Email#">#Email#</a></td>

                        <cfelse>

                        <td>Not Provided</td>

                        </cfif>

                        • 9. Re: CFELSE not executing
                          chuckbeckwith Newcomer

                          I always try to use:

                          <cfif len(trim(Email)) neq 0>

                          to prevent null/blank/space errors.

                          • 10. Re: CFELSE not executing
                            BKBK Rockstar

                            chuckbeckwith wrote:

                             

                            I always try to use:

                            <cfif len(trim(Email)) neq 0>

                            to prevent null/blank/space errors.

                            It's the same as <cfif trim(Email) NEQ "">