PDA

View Full Version : Automatically incrementing integer suffix


FraKcman
06-10-2002, 04:11 AM
Hi, I want to increment (increase by 1) on a daily basis, the suffix of a specified image.

Basically I want to report the FTSE Index on my web site using the excellent graph at http://www.international.nasdaq.com/asp/quotes_indexchart.asp?country=UK&index=UKX&lang=ENG

Trouble is, the image I want is a jpg that today is http://dynamic.international.nasdaq.com/graphs/UKX151.JPG because today is day 151 of the year. Tomorrow will be day 152 etc etc.

So how can I get my site to automatically update daily with the correct image suffix? :confused:

Can anyone help please?

scoutt
06-10-2002, 09:14 AM
unless you use a serverside language like ASP, cgi or php you won't beable to do that short of rewriting it every day.

FraKcman
06-10-2002, 05:18 PM
Ooops! I just discovered this is illegal anyway so we don't want that!

Phew!

Jon Hanlon
06-10-2002, 07:30 PM
Anyway, the way to do it would be to change the image's src property once the page loaded...

<body onload="updateImage()">
<image name="nasdaq" id="nasdaq" src="blank.gif">

<script language="Javascript">
function updateImage() {
var dayISO = getISODay();
document.images.nasdaq.src = "http://dynamic.international.nasdaq.com/graphs/UKX"
+ dayISO + ".JPG"
}

function getISODay() {
var now = new Date();
var jan1 = new Date();
jan1.setMonth(0); // 0=Jan, 1=Feb...
jan1.setDate(1); // 01/01
var dayNo = Math.floor((now.getTime() - jan1.getTime())/86400/1000) + 1
return dayNo;
}
</script>


The ISO formula for Day Number is actually a bit more complicated than this, but you get my drift.