Click to See Complete Forum and Search --> : Changing a variable


Outer
11-30-2002, 09:01 PM
I have several variables set up in my page currently. What I want is to be able to click a button on my page and have one of those variables (the date) change to the current date minus 1 (as in yesterday's date). This is because this date variable is an integral part of my picture links and I want to be able to change those links at the touch of a button to load new pictures. What's the best way to go about this?

(I've tried creating a function, but I am not familiar enough with this language to make it work properly)

gil davis
12-01-2002, 12:33 PM
<script>
var today = new Date();
var ystdy = new Date(today - (24*60*60*1000));
alert(ystdy);
</script>

Outer
12-01-2002, 01:42 PM
Hmm, maybe I should be more specific as to my question. Here's said variable I have:

var date = RightNow.getDate()

Then, I use it in some picture link that changes according to the date:

document.write("<img src=http://www.link.com/"+date+".gif>")

This loads me a nice new image each day. However, I want to be able to access previous images without changing the code. So, I created a button and I want it to run something (like a function, maybe) that turns the date into date - 1. So, the "+date+" in my link becomes yesterday's date instead of today's. Ideally, I'd like to be able to press the button again and have it keep subtracting days from the links and reloading the correct pictures, but I'll settle for what I can get. Anyone have any ideas?

gil davis
12-01-2002, 04:33 PM
You still have to construct the date correctly. Otherwise you would have to know what month it was and how many days are in that month, etc.

However, once you have used document.write() to create your link, changing the variable "date" doesn't do squat.