NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Change link dynamically via javascript help!

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-14-2006, 08:55 AM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Feb 2004
Location: Canada
Posts: 27
emalen is an unknown quantity at this point
 



Change link dynamically via javascript help!


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!
__________________
---------------------
The eMalen Design Group
dmalen@emalen.com
www.emalen.com
emalen is offline  
Old 05-14-2006, 01:48 PM   #2 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



can't you use php? I could tell you then:

PHP Code:
<?php
????: NamePros.com http://www.namepros.com/programming/197226-change-link-dynamically-via-javascript-help.html

$day 
date("l");

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

?>
then where you want the link put:
PHP Code:
<a href="<?php echo $link?>">What to watch</a>
very nice site btw!
PoorDoggie is offline  
Old 05-14-2006, 04:05 PM   #3 (permalink)
NamePros Regular
 
cvxdes's Avatar
Join Date: Oct 2005
Location: Milford MA
Posts: 692
cvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud of
 



HTML Code:
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;
cvxdes is offline  
Old 05-15-2006, 09:23 AM THREAD STARTER               #4 (permalink)
NamePros Member
Join Date: Feb 2004
Location: Canada
Posts: 27
emalen is an unknown quantity at this point
 



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
__________________
---------------------
The eMalen Design Group
dmalen@emalen.com
www.emalen.com
emalen is offline  
Old 05-15-2006, 11:16 AM   #5 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



Originally Posted by emalen
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 )

here is an even nicer script: (put this where you want the link displayed)
PHP Code:
<?php echo "<a href=\"tvguide_".date("l")."\"><img src=\"##IMAGE LOCATION HERE!!!##\"></a>"?>
That will print:
????: NamePros.com http://www.namepros.com/showthread.php?t=197226
Quote:
<a href="tvguide_monday.php"><img src="image"></a>
(monday will change depending on the day...)
PoorDoggie is offline  
Old 05-15-2006, 01:01 PM   #6 (permalink)
NamePros Regular
 
cvxdes's Avatar
Join Date: Oct 2005
Location: Milford MA
Posts: 692
cvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud ofcvxdes has much to be proud of
 



Originally Posted by emalen
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:
????: NamePros.com http://www.namepros.com/showthread.php?t=197226
<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();'
cvxdes is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 12:41 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger