473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Random background image each time the page loads

Can someone provide a sample of how to display a different background image in a table cell each time the page loads?

I am only able to find scripts to display a different picture outside a table like the one below. But how can I modify this to work as a table background? Probably need some sort of onLoad?

Any help would be greatly appreciated. Thanks in advance.
Expand|Select|Wrap|Line Numbers
  1.  ------------------------------------------------------------------- 
  2.  
  3. <script language="JavaScript">
  4. var list= new Array()
  5. list[list.length]='../images/pic_1.jpg';
  6. list[list.length]='../images/pic_2.jpg';
  7. list[list.length]='../images/pic_3.jpg';
  8. list[list.length]='../images/pic_4.jpg';
  9. list[list.length]='../images/pic_5.jpg';
  10. j=parseInt(Math.random()*list.length);
  11. j=(isNaN(j))?0:j;
  12. document.write("<img src='"+list[j]+"'>");
  13. </script>
  14.  
  15. -------------------------------------------------------------------
  16.  
Apr 16 '06 #1
1 5686
Banfa
9,065 Expert Mod 8TB
Using cascading style sheets

Get the table using var myTable = document.getElementById

then set the background style

myTable.style.backgroundImage = "url("+list[j]+")";
Apr 18 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Virus | last post by:
Ok well what I am trying to do is have 1.) the background color to change randomly with 5 different colors.(change on page load) 2,) 10 different quotes randomly fadeing in and out in random...
6
by: WJ | last post by:
Is there a way to specify background image for an Aspx page at runtime in c# ? I clicked on the Web form in the IDE (Vs.Net 2003) and it shows "DOCUMENT", which is not accessible inside code behind...
5
by: Haydnw | last post by:
Hi, I have the code below as code-behind for a page which displays two images. My problem is with the second bit of code, commented as " 'Portfolio image section". Basically, the SQL query gets...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
7
by: Brian | last post by:
Hi there I have been looking for a script that can randomly rotate 8 different images on 1 page. I used to have a script that did this but can't find it now. I have found loads of script that...
1
by: Jim in Arizona | last post by:
I created a public application based variable not within any procedure, like so: Partial Class lobbytimes_lobbytimes Inherits System.Web.UI.Page Public BackgroundImage As String Protected...
3
by: schof | last post by:
I am using the following code to call a random background image to be displayed on the far right hand side of the page ... <script type="text/javascript"> function random(n) { return...
1
by: bn4 | last post by:
I have been trying to modify a script that i had working in the past but have lost.. ORIGINAL URL: http://www.thescripts.com/forum/thread147097.html STEPS: I want it to do the following:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.