Reputation: 487
I have a "proceed" button that leads to a certain day of the week (sun-sat), I want the button to lead to the current day of the week using javascript, my site dundaah.com so far I have
<script type="text/javascript">
function myFunction() {
var d = new Date();
var links = new Array(7);
links[0] = "docs/sun.html"
links[1] = "docs/mon.html"
links[2] = "docs/tue.html"
links[3] = "docs/wed.html"
links[4] = "docs/thur.html"
links[5] = "docs/fri.html"
links[6] = "docs/sun.html"
var n = links[d.getDay()];
window.location=links[myFunction]
}
</script>
Upvotes: 0
Views: 210
Reputation: 8513
Try something like this:
<script>
function myFunction() {
var days = ["sun","mon","tue","wed","thur","fri","sat"];
window.location = days[new Date().getDay()] + ".html";
}
</script>
<button type="button" onclick="myFunction()">Today's Link</button>
Upvotes: 1
Reputation: 2027
You have to change this line. It makes no sense:
window.location=links[myFunction]
With this:
window.location=n;
Upvotes: 0