Ah, that won't work. That's because you are mixing 2 separate environments.
Javascript code runs on the client's browser, of which there could be millions. Whereas ColdFusion code runs on ColdFusion server, of which there is usually just one. In particular, the ColdFusion server know nothing of the Javascript code.
Those are the generalities. Now, on to the specifics to help you to get this to work.
From this code, I am assuming the following:
- A query has run and it contains the details of image files.
- The name of each image is a day of the week, that is, it is from the set {Monday, Tuesday, Wednesday, ..., Sunday}. In general, the query may contain multiple images named Monday, multiple images named Tuesday, and so on.
- You want code that will pick out a picture at random, whose name matches the name of the current day, and display it.
Here is some code that will do just that. It is 100% ColdFusion, involving no Javascript. 🙂
<body>
<!--- Query to fetch images and their properties --->
<cfquery name="rushedPics" datasource="myDSN">
select *
from myImgTBL
</cfquery>
<!---
Query of a query to fetch images whose name matches
today's name. There may be multiple images having a given
name.
--->
<cfquery name="rushed" dbtype="query">
select name
from rushedPics
where name like '#dateformat(now(), "dddd")#%'
</cfquery>
<cfset nrOfPics = rushed.recordcount>
<cfif nrOfPics gte 1>
<!--- Pick a random number between 1 and the total number of pictures--->
<cfset randNumber = randRange(1, nrOfPics, "SHA1PRNG")>
<!--- Relative path of randomly selected picture --->
<cfset relativePathImg = "votd/#rushed['name'][randNumber]#">
<!--- Display randomly selected picture --->
<cfoutput><img src="#relativePathImg#" width="150" height="113" border="0" alt=""></cfoutput>
</cfif>
</body>
Thanks for all the assistance I got it work now just added a table Named Banners into my own database for news etc..
Its just been awhile since I've coded in Cold Fusion