PDA

View Full Version : plz help me...


sonibhavinh
07-01-2002, 06:30 AM
Hello!

I m creating an application and in that i m having the login form which is being given an background image(.jpg). Now what i want is i m having a set of six different .jpg images and i want that everytime the user comes on the login page the background image should be changed or it should even be changed if the page is being refreshed. Help me out ...

Thanx in advance,
bhavin...

glenngv
07-01-2002, 07:24 AM
<script language="javascript">
var bg = new Array("bg1.jpg","bg2.jpg","bg3.jpg","bg4.jpg","bg5.jpg","bg6.jpg,");
function putBg(obj){
index = Math.floor(Math.random()*(bg.length-1));
this.background = bg[index];
}
</script>
</head>
<body onload="putBg(this)">

sonibhavinh
07-01-2002, 08:32 AM
The solution u gave to me is not woking. And there is no error given but yes the background remains unchanged.

joh6nn
07-01-2002, 08:39 AM
try this:

<script language="javascript">
var bg = new Array("bg1.jpg","bg2.jpg","bg3.jpg","bg4.jpg","bg5.jpg","bg6.jpg,");
function putBg(obj){
index = Math.floor(Math.random()*(bg.length-1));
obj.style.backgroundImage = bg[index];
}
</script>
</head>
<body onload="putBg(document.body)">

if that doesn't work, then you may have to change the line in bold, so that it looks like this:

obj.style.backgroundImage = "url(\"" + bg[index] + "\")";

hope that helps

sonibhavinh
07-01-2002, 10:09 AM
Thanx joh6nn it is working very well. Thanx alot...