Skip to main content
Inspiring
April 19, 2006
Answered

Dynamic data color

  • April 19, 2006
  • 6 replies
  • 894 views
Hi all, using the code attached

I have a query which is picking up responses to a form that has been submitted. The form contains 10 questions, each question is either "Yes" or "No". I would like to set it so that if the answer is "No" I would like that piece of data to show as red on the results page.... I have had a bit of help on the forum but I Just can't seem to get it to work, I get 'Variable Q1 is undefined' and I cannot see why atall...? any help please? would be appreciated many thanks
    This topic has been closed for replies.
    Correct answer Simonbullen
    After much stress and pain I discovered that CFIF wasn't working sue to spaces in the data, so I added the Trim function as you can see in the code below, all now works perfectly! thanks for all of the help

    <cfif Trim(Q1) EQ "No"><td bgcolor="##FFD6D5"><cfelse><td bgcolor="##efefef"></cfif><div align="center">#HandSReviewForm.Q1#</div></td>

    6 replies

    Participating Frequently
    April 19, 2006
    try this

    <cfoutput query="HandSReviewForm">

    <tr>
    <td>#HandSReviewForm.ID#</td>
    <td>#HandSReviewForm.departmentOrbranch#</td>
    <td>#HandSReviewForm.quarter#</td>

    <cfif Q1 EQ "No"><td "bgcolor="##ff0000"><cfelse><td bgcolor="##EFEFEF"></cfif><div align="center">#HandSReviewForm.Q1#</div></td>

    And the same for the <td> Tags that you want the colour to be dynamic

    <td><div align="center">#HandSReviewForm.Q2#</div></td>
    <td><div align="center">#HandSReviewForm.Q3#</div></td>
    <td><div align="center">#HandSReviewForm.Q4#</div></td>
    <td><div align="center">#HandSReviewForm.Q5#</div></td>
    <td><div align="center">#HandSReviewForm.Q6#</div></td>
    <td><div align="center">#HandSReviewForm.Q7#</div></td>
    <td><div align="center">#HandSReviewForm.Q8#</div></td>
    <td><div align="center">#HandSReviewForm.Q9#</div></td>
    <td><div align="center">#HandSReviewForm.Q10#</div></td>
    <td><div align="center">#HandSReviewForm.Q11#</div></td>
    <td><div align="center">#HandSReviewForm.submitted#</div></td>
    <td><div align="center">#HandSReviewForm.Unumber#</div></td>
    </tr>
    </cfoutput>
    Inspiring
    April 19, 2006
    thanks for sticking with me: see code, as you suggested - no error, but TD cell for Q1 is STILL ##CCCCCC despite the data being "No"....

    Sorry
    SimonbullenAuthorCorrect answer
    Inspiring
    April 19, 2006
    After much stress and pain I discovered that CFIF wasn't working sue to spaces in the data, so I added the Trim function as you can see in the code below, all now works perfectly! thanks for all of the help

    <cfif Trim(Q1) EQ "No"><td bgcolor="##FFD6D5"><cfelse><td bgcolor="##efefef"></cfif><div align="center">#HandSReviewForm.Q1#</div></td>
    Participating Frequently
    April 19, 2006
    try this
    <cfoutput query="HandSReviewForm">
    <cfif Q1 EQ "No">
    <tr bgcolor="##ff0000">
    <td>#HandSReviewForm.ID#</td>
    <td>#HandSReviewForm.departmentOrbranch#</td>
    <td>#HandSReviewForm.quarter#</td>
    <td><div align="center">#Q1#</div></td>
    <td><div align="center">#HandSReviewForm.Q2#</div></td>
    <td><div align="center">#HandSReviewForm.Q3#</div></td>
    <td><div align="center">#HandSReviewForm.Q4#</div></td>
    <td><div align="center">#HandSReviewForm.Q5#</div></td>
    <td><div align="center">#HandSReviewForm.Q6#</div></td>
    <td><div align="center">#HandSReviewForm.Q7#</div></td>
    <td><div align="center">#HandSReviewForm.Q8#</div></td>
    <td><div align="center">#HandSReviewForm.Q9#</div></td>
    <td><div align="center">#HandSReviewForm.Q10#</div></td>
    <td><div align="center">#HandSReviewForm.Q11#</div></td>
    <td><div align="center">#HandSReviewForm.submitted#</div></td>
    <td><div align="center">#HandSReviewForm.Unumber#</div></td>
    </tr>
    <cfelse>
    <tr bgcolor="##EFEFEF">
    <td>#HandSReviewForm.ID#</td>
    <td>#HandSReviewForm.departmentOrbranch#</td>
    <td>#HandSReviewForm.quarter#</td>
    <td><div align="center">#Q1#</div></td>
    <td><div align="center">#HandSReviewForm.Q2#</div></td>
    <td><div align="center">#HandSReviewForm.Q3#</div></td>
    <td><div align="center">#HandSReviewForm.Q4#</div></td>
    <td><div align="center">#HandSReviewForm.Q5#</div></td>
    <td><div align="center">#HandSReviewForm.Q6#</div></td>
    <td><div align="center">#HandSReviewForm.Q7#</div></td>
    <td><div align="center">#HandSReviewForm.Q8#</div></td>
    <td><div align="center">#HandSReviewForm.Q9#</div></td>
    <td><div align="center">#HandSReviewForm.Q10#</div></td>
    <td><div align="center">#HandSReviewForm.Q11#</div></td>
    <td><div align="center">#HandSReviewForm.submitted#</div></td>
    <td><div align="center">#HandSReviewForm.Unumber#</div></td>
    </tr>
    </cfif>
    </cfoutput>
    Inspiring
    April 19, 2006
    Thanks for your time dev2k i do appreciate it;

    ok, with that latest code I get all grey, I think this is because it is being applied to the whole row, where in fact each TD is outputing different data, i.e. Q1 might be No, but Q2 on the same row might be yes.... so do we need to do the same concept, but on each TD..?

    thanks once again
    Participating Frequently
    April 19, 2006
    try this
    <cfoutput query="HandSReviewForm">
    <cfif Q1 EQ "No">
    <tr bgcolor="##ff0000">
    <td>#HandSReviewForm.ID#</td>
    <td>#HandSReviewForm.departmentOrbranch#</td>
    <td>#HandSReviewForm.quarter#</td>
    <td><div align="center">#Q1#</div></td>
    <td><div align="center">#HandSReviewForm.Q2#</div></td>
    <td><div align="center">#HandSReviewForm.Q3#</div></td>
    <td><div align="center">#HandSReviewForm.Q4#</div></td>
    <td><div align="center">#HandSReviewForm.Q5#</div></td>
    <td><div align="center">#HandSReviewForm.Q6#</div></td>
    <td><div align="center">#HandSReviewForm.Q7#</div></td>
    <td><div align="center">#HandSReviewForm.Q8#</div></td>
    <td><div align="center">#HandSReviewForm.Q9#</div></td>
    <td><div align="center">#HandSReviewForm.Q10#</div></td>
    <td><div align="center">#HandSReviewForm.Q11#</div></td>
    <td><div align="center">#HandSReviewForm.submitted#</div></td>
    <td><div align="center">#HandSReviewForm.Unumber#</div></td>
    </tr>
    <cfelse>
    <tr bgcolor="##EFEFEF">
    <td>#HandSReviewForm.ID#</td>
    <td>#HandSReviewForm.departmentOrbranch#</td>
    <td>#HandSReviewForm.quarter#</td>
    <td><div align="center">#Q1#</div></td>
    <td><div align="center">#HandSReviewForm.Q2#</div></td>
    <td><div align="center">#HandSReviewForm.Q3#</div></td>
    <td><div align="center">#HandSReviewForm.Q4#</div></td>
    <td><div align="center">#HandSReviewForm.Q5#</div></td>
    <td><div align="center">#HandSReviewForm.Q6#</div></td>
    <td><div align="center">#HandSReviewForm.Q7#</div></td>
    <td><div align="center">#HandSReviewForm.Q8#</div></td>
    <td><div align="center">#HandSReviewForm.Q9#</div></td>
    <td><div align="center">#HandSReviewForm.Q10#</div></td>
    <td><div align="center">#HandSReviewForm.Q11#</div></td>
    <td><div align="center">#HandSReviewForm.submitted#</div></td>
    <td><div align="center">#HandSReviewForm.Unumber#</div></td>
    </tr>
    </cfif>
    </cfoutput>
    Participating Frequently
    April 19, 2006
    Are you trying to create the colour in the row of the TD tag.
    You need the <CFIF>statement in the Colour of the Row tag and not the TD tag.
    Something like

    <table width="100%" border="1" cellspacing="0" cellpadding="0">
    <cfoutput query="ReviewForm">
    <cfif Q1 EQ "No">
    <tr bgcolor="red">
    <td> </td>
    <td> </td>
    <td> </td>
    </tr>
    <cfelse>
    <tr bgcolor="grey">
    <td> </td>
    <td> </td>
    <td> </td>
    </tr>
    </cfoutput>
    </table>

    Inspiring
    April 19, 2006
    Well it can either be the actual text or the Bg of the cell that changes color, the later being the best. this my code for that table row:

    I now have this:

    <cfoutput query="HandSReviewForm">
    <cfif Q1 EQ "No"><tr bgcolor="##ff0000">
    <cfelse><tr bgcolor="##EFEFEF"></cfif>
    <td>#HandSReviewForm.ID#</td>
    <td>#HandSReviewForm.departmentOrbranch#</td>
    <td>#HandSReviewForm.quarter#</td>
    <td><div align="center">#Q1#</div></td>
    <td><div align="center">#HandSReviewForm.Q2#</div></td>
    <td><div align="center">#HandSReviewForm.Q3#</div></td>
    <td><div align="center">#HandSReviewForm.Q4#</div></td>
    <td><div align="center">#HandSReviewForm.Q5#</div></td>
    <td><div align="center">#HandSReviewForm.Q6#</div></td>
    <td><div align="center">#HandSReviewForm.Q7#</div></td>
    <td><div align="center">#HandSReviewForm.Q8#</div></td>
    <td><div align="center">#HandSReviewForm.Q9#</div></td>
    <td><div align="center">#HandSReviewForm.Q10#</div></td>
    <td><div align="center">#HandSReviewForm.Q11#</div></td>
    <td><div align="center">#HandSReviewForm.submitted#</div></td>
    <td><div align="center">#HandSReviewForm.Unumber#</div></td>
    </tr>
    </cfoutput>
    </table>

    but it is ahowing all as ##EFEFEF and not highlighting the "No" cells as red....

    do I need to apply this: <cfif Q1 EQ "No"><tr bgcolor="##ff0000">
    <cfelse><tr bgcolor="##EFEFEF"></cfif>
    to each TD not TR?
    Participating Frequently
    April 19, 2006
    OK
    At the top of your page you need to put this
    <cfparam name="dataColor " default="">

    this will define your varaible dataColor
    Inspiring
    April 19, 2006
    ok great thanks, no error now, but no color change either.....
    Participating Frequently
    April 19, 2006
    I am assuming that the form is sumitting the data to the database.

    try this
    Create your query first in the page where the data from the query will be displayed.
    -----------------------------------------------------------------------------------
    <cfquery name="ReviewForm" datasource="Business">
    SELECT * FROM dbo.Review ORDER BY quarter ASC
    </cfquery>
    ----------------------------------------------------------------------------

    Then between your <cfoutput query> tag
    place your
    <cfif Q1 IS "No">
    <cfset dataColor = "red">
    <cfelseif Q1 IS "Yes">
    <cfset dataColor = "grey">
    </cfif>

    Hoope this helps


    Inspiring
    April 19, 2006
    thans dev2k, yes you are right, it is from the form. Ok, I have the query at the top of my page, then the
    <cfoutput query="ReviewForm">
    <cfif Q1 IS "No">
    <cfset dataColor = "red">
    <cfelseif Q1 IS "Yes">
    <cfset dataColor = "grey">
    </cfif>

    then in the table I have <td style="color:#datacolor#">#Q1#</td> but it is returning "Variable DATACOLOR is undefined" - common error but can't see why...?

    many thanks