Solved

<tr> random colors when eventname changes

Posted on 2003-11-02
37
280 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
ID: 9666238
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
ID: 9666266
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
ID: 9666279
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
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 

Author Comment

by:phillystyle123
ID: 9666293
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
ID: 9666310
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
ID: 9666328
ok now we're getting somewhere - all the trs are the default color (black)
0
 
LVL 10

Expert Comment

by:Mause
ID: 9666359
OK now what values do #timesprices.Eventname# have???
0
 

Author Comment

by:phillystyle123
ID: 9666378
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
ID: 9666398
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
ID: 9666411
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
ID: 9666426
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
ID: 9666439
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
ID: 9666470
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
ID: 9666475
thanks mause - i'll try this out when i get back and give ya the pts.

0
 
LVL 10

Expert Comment

by:Mause
ID: 9666566
NP
let me know if you need more help

Mause
0
 

Author Comment

by:phillystyle123
ID: 9668031
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
ID: 9668719
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
ID: 9668733
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
 
LVL 10

Expert Comment

by:Mause
ID: 9669176
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
ID: 9669194
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
ID: 9669269
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
ID: 9669355
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
ID: 9669426
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
ID: 9669493
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
ID: 9669800
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
ID: 9669829
You can delete the color from the list let me work this out
0
 
LVL 10

Accepted Solution

by:
Mause earned 100 total points
ID: 9669839
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
ID: 9670160
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
ID: 9670188
in style you don't need the # so it is

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

Expert Comment

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

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

Author Comment

by:phillystyle123
ID: 9670745
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
ID: 9670990
What is the code you have now????
0
 
LVL 10

Expert Comment

by:Mause
ID: 9671158
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
ID: 9671277
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
ID: 9671326
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
ID: 9671570
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
ID: 9672909
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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