...

View Full Version : date loop



kiwis
11-04-2012, 05:29 AM
i'm trying to get my date in increase my 1 month on a set interval but it does not work, what can I do here?



<script type="text/javascript">

var myDate = new Date(1960,1,1);
var myVar=setInterval(function(){myTimer()},1000);

function myTimer(){
var nDate = new Date(myDate.getMonth()+1);
alert(nDate);

}

</script>

devnull69
11-04-2012, 09:10 AM
function myTimer(){
myDate.setMonth(myDate.getMonth()+1);
alert(myDate);
}

Philip M
11-04-2012, 09:37 AM
Better write the output to a <span> rather than use an alert, as otherwise with one second interval you will not be able to stop it without restarting the browser.


<span id = "theDate"></span>

<script type="text/javascript">
var myDate = new Date(1960,1,1);
document.getElementById("theDate").innerHTML = myDate;
setInterval(myTimer,1000)

function myTimer(){
myDate.setMonth(myDate.getMonth()+1);
document.getElementById("theDate").innerHTML = myDate;

}
</script>

felgall
11-04-2012, 09:42 PM
Better write the output to a <span> rather than use an alert, as otherwise with one second interval you will not be able to stop it without restarting the browser.

That's why there's an extra checkbox in the bottom of the alert in some browsers - so you can stop the constant debugging alerts from popping up without having to restart the browser.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum