Solved

<tr> random colors when eventname changes

Posted on 2003-11-02
37
277 Views
Last Modified: 2013-12-24
i need my table rows to randomly change colors based on my color parameters.  is there some sort of cfstylesheet i can use for this? or is there another way?
0
Comment
Question by:phillystyle123
  • 19
  • 13
  • 5
37 Comments
 
LVL 10

Expert Comment

by:Mause
Comment Utility
Hi there

No there is noting like cfstylesheet!
I don''t know when your color changes but I gues the color is based on value of a CF-variable
If this is true it will be something like this:

<cfswitch expression="#VARIABLE#">
   <cfcase value="value1">
         <CFSET color='RED'>
   </cfcase>
   <cfcase value="value2">
         <CFSET color='BLUE'>
   </cfcase>
   <cfcase value="value3">
         <CFSET color='ORANGE'>
   </cfcase>
   <cfdefaultcase>
           <CFSET color='BLACK'>
   </cfdefaultcase>
</cfswitch>

and then in your table
<CFOUTPUT>
<TR style="color:#color#;">
 <TD>...............</TD>
</TR>
</CFOUTPUT>

You can also do this width style-clases so in the switch you replace
<CFSET color='BLACK'>
width:
<CFSET colorclass='class_red'>

and in your table
<TR style="color:#color#;">
width:
<TR class="#colorclass#">

hope this helps, let me know
Mause
0
 

Author Comment

by:phillystyle123
Comment Utility
this is what i have so far (i'm not getting any errors but i'm also not getting random table row colors:

<cfswitch expression="#timesprices.Eventname#">
   <cfcase value="value1">
         <CFSET color='RED'>
   </cfcase>
   <cfcase value="value2">
         <CFSET color='BLUE'>
   </cfcase>
   <cfcase value="value3">
         <CFSET color='ORANGE'>
   </cfcase>
   <cfdefaultcase>
           <CFSET color='BLACK'>
   </cfdefaultcase>
</cfswitch>
            <cfoutput query="timesprices" group="Eventname">
                    <tr style="color:#color#;">
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
you have to put the <cfoutput query="timesprices" group="Eventname"> before the cfswitch
else he get only the first result not every row.

so

<cfoutput query="timesprices" group="Eventname">

<cfswitch expression="#timesprices.Eventname#">
   <cfcase value="value1">
         <CFSET color='RED'>
   </cfcase>
   <cfcase value="value2">
         <CFSET color='BLUE'>
   </cfcase>
   <cfcase value="value3">
         <CFSET color='ORANGE'>
   </cfcase>
   <cfdefaultcase>
           <CFSET color='BLACK'>
   </cfdefaultcase>
</cfswitch>
.
.
<tr style="color:#color#;">
.
.
</cfoutput>

greetings,
Mause
0
 

Author Comment

by:phillystyle123
Comment Utility
thanks mause but still no change - no color in any row  - this is my code:

<cfoutput query="timesprices" group="Eventname">
            <cfswitch expression="#timesprices.Eventname#">
   <cfcase value="value1">
         <CFSET color='RED'>
   </cfcase>
   <cfcase value="value2">
         <CFSET color='BLUE'>
   </cfcase>
   <cfcase value="value3">
         <CFSET color='ORANGE'>
   </cfcase>
   <cfdefaultcase>
           <CFSET color='BLACK'>
   </cfdefaultcase>
</cfswitch>

                    <tr style="color:#color#;">
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
hhmm sorry try this:


<cfoutput query="timesprices" group="Eventname">
          <cfswitch expression="#timesprices.Eventname#">
   <cfcase value="value1">
         <CFSET color='Red'>
   </cfcase>
   <cfcase value="value2">
         <CFSET color='Blue'>
   </cfcase>
   <cfcase value="value3">
         <CFSET color='Orange'>
   </cfcase>
   <cfdefaultcase>
           <CFSET color='Black'>
   </cfdefaultcase>
</cfswitch>

<tr style="background-color:#color#;">
0
 

Author Comment

by:phillystyle123
Comment Utility
ok now we're getting somewhere - all the trs are the default color (black)
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
OK now what values do #timesprices.Eventname# have???
0
 

Author Comment

by:phillystyle123
Comment Utility
oh ok - i think i see what you mean -

one of my event names is "Morton Subotnick with Tony Martin"

i stuck that in as "Value1" and the tr is red. so that works, except i need it to be dynamic so it knows an Eventname is different and assigns a new color to the table row because i'm going to continue to add Eventnames.  
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
so there are no default eventnames?

OK what are your color parameters?
Do you also fill in a color when you add a new eventname?
or do you want a random color on every row?
0
 

Author Comment

by:phillystyle123
Comment Utility
i think a random color for every row will be fine but just in case - how would i fill in a color when i add a new eventname - database field?
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
Yes, you then need an extra database field
so your table would look something like this:
id - int
eventname - varchar(255)
eventcolor - varchar(15)

and an extra input field in you new event form called color
You can make this filed free text or a drop down field width all the collors you want

if you have this then forget the cfswitch and the row would look like this:
<tr style="background-color:#eventcolor#;">
0
 

Author Comment

by:phillystyle123
Comment Utility
can i make it random without adding the db field? so, not assigning specific colors in the db just having the tr change colors based on the eventname variable?
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
what do you want random or based on the eventname??

Random you can do something like this:
make a list of all colors:
<cfset allcolors="red,blue,green, black, orange">

and then
<tr style="background-color:#listgetat(allcolors, RandRange(1,listlen(allcolors, ","), ","))#;">

If you want the color be based on eventname then use the cfswitch
but then you need to know somehow the eventnames

or do you have something like an event type??? so every eventtype is a color
0
 

Author Comment

by:phillystyle123
Comment Utility
thanks mause - i'll try this out when i get back and give ya the pts.

0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
NP
let me know if you need more help

Mause
0
 

Author Comment

by:phillystyle123
Comment Utility
hi mause - i'm back and i tried out the code - here's the error:

Mause
The function RandRange takes 2 arguments(s)


The error occurred while processing an element with a general identifier of (#listgetat(allcolors, RandRange(1,listlen(allcolors, ","), ","))#), occupying document position (375:29) to (375:93).


Date/Time: Mon Nov 03 02:05:11 2003
Browser: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)
Remote Address: 141.151.20.20
HTTP Referrer: http://redcatweb2.org/calendar/event.cfm?Eventname=Morton%20Subotnick%20with%20Tony%20Martin

here's the code i used:

<cfset allcolors="red,blue,green, black, orange">
<tr style="background-color:#listgetat(allcolors, RandRange(1,listlen(allcolors, ","), ","))#;">



0
 
LVL 11

Expert Comment

by:hart
Comment Utility
just try this

<cfset allcolors="red,blue,green,black,orange">
<tr style="background-color:#listgetat(allcolors, RandRange(1,listlen(allcolors))#;">

Regards
Hart
0
 
LVL 11

Expert Comment

by:hart
Comment Utility
or u could write directly bgcolor no need to write style [bcos it doesn't work in earlier versions of  NS 4.7]

<tr bgcolor="#listgetat(allcolors, RandRange(1,listlen(allcolors))#">

Regards
Hart
0
Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

 
LVL 10

Expert Comment

by:Mause
Comment Utility
sorry replace it width this:

<tr style="background-color:#listgetat(allcolors, RandRange(1,listlen(allcolors, ',')), ',')#;">

I placed one ) at the wrong position..


Hart you also miss one ) of listgetat at the end
0
 
LVL 11

Expert Comment

by:hart
Comment Utility
yeah u r right mause i missed one ) too :-)

but why the style tag when it can be done with bgColor???

Regards
Hart
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
Yes you can use that one to but I rather use style I think its easier and because he wanted something like stylesheet (well cfstylesheet)

0
 
LVL 11

Expert Comment

by:hart
Comment Utility
if style sheet was required then
u should have given him a class,

but its ok it doesn't matter, ur solution will work gr8 :-)

the only reason why i said this was bcos it won't some times work in versions of NS.
but if he is not bothered about cross browser compatibilities, then its ok..

just forget my comments and i will move on
have a gr8 day :-)

Regards
Hart

0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
I know about the class I said that in one of my first posts
but I did not want to make a class for every color that why I used style...

And no hard feelings you're a great expert

Mause
0
 
LVL 11

Expert Comment

by:hart
Comment Utility
u don't have to make different classes fro different color.
u could have just assigned the #color# variable in the class.

anywayz forget it, bcos of me this thread has become toooo long,
thats no help to u ;-)

thanks for the compliment, feels great to hear one from good experts like you :-)

Regards
Hart
0
 

Author Comment

by:phillystyle123
Comment Utility
both ideas (hart, mause) work but i think i am going to go with style. have a ? though: is there a way to make sure the same color doesn't get assigned to two consecutive rows?
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
You can delete the color from the list let me work this out
0
 
LVL 10

Accepted Solution

by:
Mause earned 100 total points
Comment Utility
here you go:

<CFSET getrandomcolor = RandRange(1,listlen(allcolors, ','))>
<tr style="background-color:#listgetat(allcolors, getrandomcolor, ',')#;">
<CFSET allcolors = listdeleteat(allcolors,getrandomcolor)>

But then make sure there are enough colors in the list as there are rows else you will get an error
0
 

Author Comment

by:phillystyle123
Comment Utility
how can i work this into it:

<cfset allcolors="##cccccc,##d4d590,##c2bb9c,##e4eae9,##c4ae5a">

(these are the colors i need to be random)
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
in style you don't need the # so it is

<cfset allcolors="cccccc,d4d590,c2bb9c,e4eae9,c4ae5a">
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
hhmmm
<cfset allcolors="##cccccc,##d4d590,##c2bb9c,##e4eae9,##c4ae5a">

will work I gues i don't understand you?
0
 

Author Comment

by:phillystyle123
Comment Utility
sorry to be such a huge hassle mause but it's still assigning back to back <tr>s with the same color: here's the link so you can see what i mean:

http://redcatweb2.org/calendar/timesprices.cfm
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
What is the code you have now????
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
you only have 5 colors if you have more records (rows) then there is a problem if you use this code

<CFSET getrandomcolor = RandRange(1,listlen(allcolors, ','))>
<tr style="background-color:#listgetat(allcolors, getrandomcolor, ',')#;">
<CFSET allcolors = listdeleteat(allcolors,getrandomcolor)>

because it will give you an error on row 6 => there are no more colors in the list

Or do you want to use only these 5 colors?? and show them like this:
row 1 - color1
row 2 - color2
row 3 - color3
row 4 - color4
row 5 - color5
row 6 - color1
row 7 - color2
row 8 - color3
row 9 - color4
row 10 - color5

then it wil be like this:
<tr style="background-color:#listgetat(allcolors, (timesprices.curentrow mod listlen(allcolors))+1, ',')#;">
0
 

Author Comment

by:phillystyle123
Comment Utility
i'm still getting back to back rows with the same color:

here's my code:

<cfoutput query="timesprices" group="Eventname">
                        <cfset allcolors="##cccccc,##d4d590,##c2bb9c,##e4eae9,##c4ae5a">
                        
            
            

            <tr style="background-color:#listgetat(allcolors, (timesprices.currentrow mod listlen(allcolors))+1, ',')#;">
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
what do you mean width: back to back rows ?

You getting the same colors because you have 19 records (rows) and only 5 colors
so the first 5 rows have a different color but then what color do you want to give the other 14 rows?
0
 

Author Comment

by:phillystyle123
Comment Utility
got ya - so there's really no way to assign 5 colors to a dynamically generated table rows if the number of rows is going to be constantly changing. your code works great - it's just i was hoping not to have two consecutive rows be the same color. unfortunately, i only have 5 colors to work with.  
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
Thx,

Maybe this is an option:
Only display 5 records and a next page buttun to the next 5 records so that there are only 5 rows to display width 5 differnt colors

Mause
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now