DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   Alternating backgrounds? (http://www.daniweb.com/forums/thread29187.html)

BT2005 Jul 27th, 2005 4:48 pm
Alternating backgrounds?
 
hey all, i was wondering if anyone has the code for "Alternating backgrounds", i dont know if that is the term for it, but its where you load a page, and the background is differnt everytime you load that page, do you follow?, well im very new to html and all that, so please dont flip out if i used the wrong words and such :cheesy:

cscgal Jul 27th, 2005 4:59 pm
Re: Alternating backgrounds?
 
Well, suppose you had an HTML table ... you would just tell one row to be one color and the next row to be a different color. Are you talking more along the lines of a dynamic script that generates content on-the-fly?

BT2005 Jul 27th, 2005 5:02 pm
Re: Alternating backgrounds?
 
i wanted some thing like this, http://pegase.foxalpha.com/

reload the page and see how the background image always changes.

I would i do that?

tgreer Jul 27th, 2005 6:04 pm
Re: Alternating backgrounds?
 
You can do this a variety of ways. To give you the best answer, we need to know more about you and your capabilities.

For example, do you do any server-side coding at all? PHP, for example? Or do you want to do this all with client-side code?

BT2005 Jul 27th, 2005 6:25 pm
Re: Alternating backgrounds?
 
well as i said before, im pretty new, i am good with html and can understand most of it, if you could post the easiest way to do this, then ill give it a shot, I greatly appreciate it.

tgreer Jul 27th, 2005 6:32 pm
Re: Alternating backgrounds?
 
It depends. The easiest way is with server-side code. You can't do it with plain HTML.

BT2005 Jul 27th, 2005 6:38 pm
Re: Alternating backgrounds?
 
alright, ill do it server side code

tgreer Jul 27th, 2005 7:47 pm
Re: Alternating backgrounds?
 
Great! Then I suggest you ask the question in the appropriate server-side coding forum. If you're new to it, then I suggest PHP. PHP works by interspersing PHP tags with your HTML tags. When a user browses to a PHP page, the server first interprets the PHP.

So to generate an alternate image, you might have something that looks like:

<img src="<?php $myVariableImage ?>">

The trick, then, is to write PHP code that changes the value of the $myVariableImage string. So, armed with that little bit of foreknowledge, I suggest you go to the PHP forum and ask some questions there.

alpha_foobar Jul 27th, 2005 8:28 pm
Re: Alternating backgrounds?
 
no reason why you couldn't do this with javascript, Math.random and the window onload event.

tgreer Jul 27th, 2005 11:47 pm
Re: Alternating backgrounds?
 
Yes, that's a client-side approach. You'd have to pre-load graphics. I think the server-side approach is more straightforward. And, as the O.P. was new to web development, I thought he should be exposed to server-side coding. But the thread would benefit from seeing a JavaScript code snippet, if you'd care to post one!


All times are GMT -4. The time now is 8:45 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC