Jump to content

Images -> Dates


Mythirion
 Share

Recommended Posts

Drop this whole chunk of code exactly where you want the image. There are better ways to organize it, but this is the simplest.

			<img id="rotating">			<script type="text/javascript">				function set_pic () {					var pix = [];					pix[0] = "someimage.gif";					pix[1] = "someimage.gif";					pix[2] = "someimage.gif";					pix[3] = "someimage.gif";					pix[4] = "someimage.gif";					pix[5] = "someimage.gif";					pix[6] = "someimage.gif";					var date = new Date ();					var index = date.getDay(); // SUNDAY IS 0					document.getElementById("rotating").src = pix[index];				}				set_pic ();			</script>

Link to comment
Share on other sites

Oops ignore me - Array extends Object.

var test = []; alert(typeof(test));test = new Array(); alert(typeof(test));

Link to comment
Share on other sites

Hi Synook,That's intresting both are objects, Array extends object and [] (is this predefined object? should I call it block brackets hehehe)?.I have no idea, this is new to me.Also, I am enjoying the "typeof()" thing! thank you.

Link to comment
Share on other sites

[] is JSON syntax for "object". http://www.json.org/{} is JSON syntax for "array", but as in JS arrays are also objects (variable['a'] === variable.a) you can use either.
I think you have that backwards, the curly brackets {} are for objects, the square brackets [] are for arrays. It says so right on the page you just linked (and it seemed more logical to me to begin with).
Link to comment
Share on other sites

Drop this whole chunk of code exactly where you want the image. There are better ways to organize it, but this is the simplest.
			<img id="rotating">			<script type="text/javascript">				function set_pic () {					var pix = [];					pix[0] = "someimage.gif";					pix[1] = "someimage.gif";					pix[2] = "someimage.gif";					pix[3] = "someimage.gif";					pix[4] = "someimage.gif";					pix[5] = "someimage.gif";					pix[6] = "someimage.gif";					var date = new Date ();					var index = date.getDay(); // SUNDAY IS 0					document.getElementById("rotating").src = pix[index];				}				set_pic ();			</script>

And in the pix 'Someimage' I just drop each image?
Link to comment
Share on other sites

I think you have that backwards, the curly brackets {} are for objects, the square brackets [] are for arrays. It says so right on the page you just linked (and it seemed more logical to me to begin with).
You are right :) I was thinking of TI-BASIC 64k.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...