Unstoppable Domains โ€” Get your daily AI drops report

Change link dynamically via Javascript help!

SpaceshipSpaceship
Watch

emalen

Established Member
Impact
0
I'd like to know if there is a javascript that will change a link url on my page depending on what day of the week it is.

i have a site http://www.thetvaddict.com

on the sidebar there is a 'what to watch guide'

i'd like to be able to change the link to the new day of the week, automatically, depending on the day.

thanks for the help!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
can't you use php? I could tell you then:

PHP:
<?php

$day = date("l");

$link = "http://domain.com/link.php?day=$day";

?>
then where you want the link put:
PHP:
<a href="<?php echo $link; ?>">What to watch</a>

very nice site btw!
 
0
•••
HTML:
var d = new Date()
switch(d.getDay()){
	case 0:	link = "Sunday's link"; break
	case 1:	link = "Monday's link"; break
	case 2:	link = "Tuesday's link"; break
	case 3:	link = "Wednesday's link"; break
	case 4:	link = "Thursday's link"; break
	case 5:	link = "Fridays's link"; break
	case 6:	link = "Saturday's link"; break
}
document.getElementById("The ID of your link").src = link;
 
0
•••
thanks for the responses, i'm not a coding expert

cvxdes: where do I place that code in my html

right now the link i'm using is (i've shortened it as an example)

<a href="tvguide_tuesday.php"><img src="image"></a>

I change the day everyday.... how do i implement your code?

thanks
 
0
•••
emalen said:
thanks for the responses, i'm not a coding expert

cvxdes: where do I place that code in my html

right now the link i'm using is (i've shortened it as an example)

<a href="tvguide_tuesday.php"><img src="image"></a>

I change the day everyday.... how do i implement your code?

thanks
hi - seriously, why don't you use php? it is a much nicer script: (no offence cvxdes :lol: )

here is an even nicer script: (put this where you want the link displayed)
PHP:
<?php echo "<a href=\"tvguide_".date("l")."\"><img src=\"##IMAGE LOCATION HERE!!!##\"></a>"; ?>
That will print:
<a href="tvguide_monday.php"><img src="image"></a>
(monday will change depending on the day...)
 
0
•••
emalen said:
thanks for the responses, i'm not a coding expert

cvxdes: where do I place that code in my html

right now the link i'm using is (i've shortened it as an example)

<a href="tvguide_tuesday.php"><img src="image"></a>

I change the day everyday.... how do i implement your code?

thanks

put this in your header:
<script type='text/javascript'>
function assignlink(){var d = new Date()
switch(d.getDay()){
case 0: link = "Sunday's link"; break
case 1: link = "Monday's link"; break
case 2: link = "Tuesday's link"; break
case 3: link = "Wednesday's link"; break
case 4: link = "Thursday's link"; break
case 5: link = "Fridays's link"; break
case 6: link = "Saturday's link"; break
}
document.getElementById("The ID of your link").src = link;
}
</script>

And, IF you have a onload property in your Body tag, add this to the end: assignlink();

If not, add this to your body tag:
onload='assignlink();'
 
0
•••
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back