Mythirion Posted December 14, 2008 Share Posted December 14, 2008 I can get where a page shows the date, but I need to get where the date is shown with an image. So on Monday it'll show one image but on another day, it shows a different picture... Link to comment Share on other sites More sharing options...
jeffman Posted December 15, 2008 Share Posted December 15, 2008 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 More sharing options...
inktherapy Posted December 15, 2008 Share Posted December 15, 2008 Hi Deirdre's Dad,In your sample above, the variable pix = [ ]; is that the same as array? Thanks. Link to comment Share on other sites More sharing options...
Synook Posted December 15, 2008 Share Posted December 15, 2008 Oops ignore me - Array extends Object. var test = []; alert(typeof(test));test = new Array(); alert(typeof(test)); Link to comment Share on other sites More sharing options...
inktherapy Posted December 15, 2008 Share Posted December 15, 2008 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 More sharing options...
Synook Posted December 15, 2008 Share Posted December 15, 2008 [] 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. Link to comment Share on other sites More sharing options...
Ingolme Posted December 15, 2008 Share Posted December 15, 2008 [] 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 More sharing options...
Mythirion Posted December 15, 2008 Author Share Posted December 15, 2008 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 More sharing options...
jeffman Posted December 15, 2008 Share Posted December 15, 2008 And in the pix 'Someimage' I just drop each image?Yes. Link to comment Share on other sites More sharing options...
Mythirion Posted December 18, 2008 Author Share Posted December 18, 2008 Yes.Okay, thank you so much. Link to comment Share on other sites More sharing options...
Synook Posted December 19, 2008 Share Posted December 19, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.