...

View Full Version : NEED Urget Help With Timer



kimstanely
05-05-2006, 07:07 PM
Hi,


Is there a way that i can update something, after 2 weeks, i think we can do this by using timer but i am having a little problem doing that. Can some ont please help!!!!

Thanks
Kim

Philip M
05-05-2006, 07:41 PM
We need more information to give a helpful reply.

What do you mean "update something after one day". Update what? Every day or just once?

I am sure that one of our onts will assist you! ;)

kimstanely
05-05-2006, 07:51 PM
See this peice of code changes an image hyperlink and alt tag after evey 1 seconds i want it to change after evey i day, the problem is that when i close the window evything starts from beginning i dont want it to do that:





<HTML><HEAD>

<SCRIPT LANGUAGE="JavaScript">

var timer = null
var counter =0
function showImage() {
timer=setTimeout("showImage()", 10000);
counter++;

if (counter >= pic.length)
counter = 1;
document.pictures.src = pic[counter].src;
elementA=document.getElementById('image2');
elementA.setAttribute('alt', alttextArray[counter]);
var textA = summaryArray[counter];
document.getElementById('text').innerHTML = textA;
document.getElementById('links').href = linkArray[counter];
}

if (document.images) {

pic = new Array()

pic[0] = new Image(108, 108);
pic[0].src = "flag_col.jpg";

pic[1] = new Image(108, 108);
pic[1].src = "books_glasses.jpg";

pic[2] = new Image(108, 108);
pic[2].src = "lawyers_steps.jpg";

pic[3] = new Image(108, 108);
pic[3].src = "pen_book.jpg";

pic[4] = new Image(108, 108);
pic[4].src = "scales1.jpg";

pic[5] = new Image(108,108);
pic[5].src = 'ccs.gif'

pic[6] = new Image(108,108);
pic[6].src = 'sj_e.gif'

}
var alttextArray = new Array()
alttextArray[0] = 'This 1'
alttextArray[1] = 'This 2'
alttextArray[2] = 'This 3'
alttextArray[3] = 'This 4'
alttextArray[4] = 'This 5'
alttextArray[5] = 'This 6'
var summaryArray = new Array()

summaryArray[0] = 'Lalal '
summaryArray[1] = 'a'
summaryArray[2] = 'b'
summaryArray[3] = 'c'
summaryArray[4] = 'd>'
summaryArray[5] = 'e'
summaryArray[6] = 'f'

var linkArray = new Array()
linkArray[0] = 'www.yahoo.com'
linkArray[1] = 'www.hotmail.com'
linkArray[2] = 'www.yahoo.com'
linkArray[3] = 'www.yahoo.com'
linkArray[4] = 'www.yahoo.com'
linkArray[5] = 'www.yahoo.com'
linkArray[6] = 'www.yahoo.com'

document.write('<td height="65" valign="top" cellpadding="2" border="1">')
document.write('<IMG SRC="flag_col.jpg" WIDTH="108" HEIGHT="108" NAME="pictures" id="image2" alt="What">');
document.write('</td>')
document.write('<p>')
document.write('<a href="" id="links">')
document.write('<div id="text"> </div>')
document.write('</a>');

// - End of JavaScript - -->
</SCRIPT>
</HEAD>

<BODY BACKGROUND="FFFFFF">


<script type="text/javascript" language="javascript">
showImage();
</script>
</BODY>
</HTML>





Thanks in advance Sorry i did not post this before

Kim

boxxer03
05-05-2006, 08:32 PM
You won't be able to do it with a timer, because a timer only runs while a user is on the page and then resets once they leave. The only way I could think of doing it would be to use the date, but you would have to find a way to relate the date to a picture.

Beagle
05-08-2006, 10:03 PM
ok, so here's a decent enough idea.

Get all your images into an array.

Then, get the day of the year.

Then use modulo on the length of the array and day of year to determine your array index.



var pic;

if (document.images)
{
pic = new Array()

pic[0] = new Image(108, 108);
pic[0].src = "flag_col.jpg";

pic[1] = new Image(108, 108);
pic[1].src = "books_glasses.jpg";

pic[2] = new Image(108, 108);
pic[2].src = "lawyers_steps.jpg";

pic[3] = new Image(108, 108);
pic[3].src = "pen_book.jpg";

pic[4] = new Image(108, 108);
pic[4].src = "scales1.jpg";

pic[5] = new Image(108,108);
pic[5].src = 'ccs.gif'

pic[6] = new Image(108,108);
pic[6].src = 'sj_e.gif'
}

function getImageByDayOfYear(p_day)
{
if (pic.length && pic.length > 0)
{
return pic[(p_day - 1)%pic.length];
}
else
{
return null;
}
}

Date.prototype.getDayOfYear = function() {
var Y = this.getFullYear(), M = this.getMonth(), D = this.getDate();
return (Date.UTC(Y, M, D) - Date.UTC(Y, 0, 0)) / 86400000;
};

var doy = new Date();
var imageToDisplay = getImageByDayOfYear(doy.getDayOfYear());


DOY code from: http://www.merlyn.demon.co.uk/js-date8.htm#DoY

kimstanely
05-09-2006, 02:27 PM
hi Beagle,

When i placed this code in the head it doesn't do anything. is there something i need to do?

Thanks for the help,
Kim

kimstanely
05-09-2006, 08:43 PM
Hi Beagle,

Can i do this by using asp, if it can , could you please show me a little example.

Thanks
kim

Beagle
05-09-2006, 08:48 PM
What do you mean it doesn't work?

If you want to paste the errors you get, we can help you from there.

As for ASP, I'm more experienced in PHP, better ask once you get the javascript down in the ASP forum.

boxxer03
05-09-2006, 09:46 PM
Hi,


Is there a way that i can update something, after 2 weeks, i think we can do this by using timer but i am having a little problem doing that. Can some ont please help!!!!

Thanks
Kim

I seen that you edited your first post from daily to bi-weekly (you can see the last edited tag under your post). I would suggest that if you want to get help that is relevant to what you wanna do that you decide for sure how often the picture needs to change. Because you have another post on here for the same thing, but changing the pictures after a certain amount of seconds.

kimstanely
05-10-2006, 02:11 PM
Hi beagle,

Could you please let me know where should i place the Script you gave.
Because when i copy the code you gave and pasted it in my file there was no error but the page was blank

Thanks,
Kim

Beagle
05-10-2006, 04:26 PM
Kim,
You need to put the script I gave you in script tags in the head of the document.

Then you need to call the getImageByDayOfYear to get the image you want.

something like:



<body onload="document.getElementById('img1').src = getImageByDayOfYear((new Date()).getDayOfYear()).src;">

kimstanely
05-10-2006, 06:05 PM
hi,

Thanks beagle, it works but the first who images flash before they change. Also can i set it to work that the image change after 2 weeks.


Thanks for all the help.

Kim



<html>
<head>
<script type="text/javascript">
var pic;

if (document.images)
{
pic = new Array()

pic[0] = new Image(108, 108);
pic[0].src = "flag_col.jpg";

pic[1] = new Image(108, 108);
pic[1].src = "books_glasses.jpg";

pic[2] = new Image(108, 108);
pic[2].src = "lawyers_steps.jpg";

pic[3] = new Image(108, 108);
pic[3].src = "pen_book.jpg";

pic[4] = new Image(108, 108);
pic[4].src = "scales1.jpg";

pic[5] = new Image(108,108);
pic[5].src = 'ccs.gif'

pic[6] = new Image(108,108);
pic[6].src = 'sj_e.gif'
}

function getImageByDayOfYear(p_day)
{
if (pic.length && pic.length > 0)
{
return pic[(p_day - 1)%pic.length];
}
else
{
return null;
}
}

Date.prototype.getDayOfYear = function() {
var Y = this.getFullYear(), M = this.getMonth(), D = this.getDate();
return (Date.UTC(Y, M, D) - Date.UTC(Y, 0, 0)) / 86400000;
};

var doy = new Date();
var imageToDisplay = getImageByDayOfYear(doy.getDayOfYear());

</script>
</head>

<body onload="document.getElementById('img1').src = getImageByDayOfYear((new Date()).getDayOfYear()).src;">

<img src="pen_book.jpg" id="img1">
</body>

</html>

Beagle
05-10-2006, 06:56 PM
you can modify the code to do whatever you want...

Right now, you're going off of the day of the year. You could divide that number by 14 rounded down to get every two weeks.

as for the flickering of the initial img, try not giving a source at all when you create it in the html. just <img src="" />

That might help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum