473,804 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random Background image for a table - IMAGE ARRAY

2 New Member
What I am trying to accomplish is to have the background image of a table change every time a page is reloaded/refreshed. I have tried many different scripts and non of them have worked for me. I have a total of four images at the moment that will be used in this array.

Any and all help would be greatly appreciated.


Thanks in advance,
May 15 '07 #1
2 6154
iam_clint
1,208 Recognized Expert Top Contributor
Example
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. window.onload = function() {
  3. var bimages = ["img1.gif", "img2.gif", "img3.gif", "img4.gif"];
  4. var rand=Math.floor(Math.random()*4);
  5. newImage = "url(backgrounds/"+bimages[rand]+")";
  6. document.getElementById('table').style.backgroundImage = newImage;
  7. }
  8. </script>
  9. <table id="table" border=1 width=200 height=200>
  10. <tr><td align="center">Hi</td></tr>
  11. </table>
  12.  
May 15 '07 #2
jemedina74
2 New Member
Clint,


Thank you so much that worked perfect.


Regards,


jemedina74


Example
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. window.onload = function() {
  3. var bimages = ["img1.gif", "img2.gif", "img3.gif", "img4.gif"];
  4. var rand=Math.floor(Math.random()*4);
  5. newImage = "url(backgrounds/"+bimages[rand]+")";
  6. document.getElementById('table').style.backgroundImage = newImage;
  7. }
  8. </script>
  9. <table id="table" border=1 width=200 height=200>
  10. <tr><td align="center">Hi</td></tr>
  11. </table>
  12.  
May 15 '07 #3

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

Similar topics

3
18847
by: MediaDesign | last post by:
so there's the problem: my text links have background images and when I put links around images on my page, they too get the background image treatment which I do not...I have tried several possible solutions and nothing has worked: my html code: <div class="borderCCC"> <div class="clients"><a href="../index.html"><img
13
3973
by: Giggle Girl | last post by:
Hi there, I need to use a background image in a TR that does NOT restart everytime it hits a TD. Can it be done? Specifically, if you set a background image for an entier table, now mater how many TRs and TDs you have, it will show the complete/unfragmented image (as long as you don't over-ride it). When I set a TR background image, every time I hit a TD it "re-seeds" the image. I want to have a TR that shows an 800px image in it's
6
41624
by: Luis Arvayo | last post by:
Hello, I am trying to convert a jpeg image stored in a PictureBox to a byte array in order to later save it to a database, but I get this error : "Generic Error in GDI+". The source code is the following (when clicking in a button): MemoryStream ms = new MemoryStream(); pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); //
2
1535
by: Deasun | last post by:
Heres the code I have: Dim objTheStream As MemoryStream = New MemoryStream Dim objPhoto As Image = pic_PhotoToUpload.Image() With objPhoto .Save(objTheStream, System.Drawing.Imaging.ImageFormat.Jpeg) End With Dim objByteToSend(objTheStream.Length) As Byte objByteToSend = objTheStream.ToArray()
0
3132
by: aparth | last post by:
I've been trying and failing to create an image map that contains a tiled background image underneath the main image. My image map is 600px in height. I want the main image (img_bottom.jpg) to only cover the bottom 100px of the map (and the background to fill the rest of the space). The height of the main image will change, which is why I want to leave the empty space as a tiled background image. #my_map { display: block; height:...
1
1456
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 Sub Page_Load(ByVal ..)
3
2747
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 Math.floor((Math.random() % 1) * n); } document.documentElement.style.background="url('photo"++".jpg') repeat-y 890px 0 background-attachment: fixed" </script> This is working fine in explorer - but does not bring up the image in safari or mozilla ... any...
0
827
by: peerraghu | last post by:
hi how to create image table in the SQL database, i wrote small querry just look at these CREATE TABLE Product_image1 ( IDENTITY (1, 1) NOT NULL , NOT NULL , (50), NULL , (50) )
1
2620
by: anmcafresher | last post by:
Hi Guys, I am working with an option where I do want to print a background image without enabling the "Print Background Color and Image" in the IE. I do want to get this image printed on each page that i get printed through Printer like a footer.
2
3886
by: zceef05 | last post by:
I want to know how we could convert an image into an array of numbers. Furthemore coud you pleezzzzz tell me how we cud rotate this matrix ( please note te commands of java shud be rotating the matrix by 90 degrees) this shud eventually rotate the image too. Pleezz reply as early as possible pleezzz.
0
9571
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.