[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 05-14-2006, 07:55 AM   #1 (permalink)
NamePros Member
 
Join Date: Feb 2004
Location: Canada
Posts: 27
42.00 NP$ (Donate)

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, 12:48 PM   #2 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie 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

$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, 03:05 PM   #3 (permalink)
NamePros Regular
 
cvxdes's Avatar
 
Join Date: Oct 2005
Location: Milford MA
Posts: 692
96.45 NP$ (Donate)

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, 08:23 AM   #4 (permalink)
NamePros Member
 
Join Date: Feb 2004
Location: Canada
Posts: 27
42.00 NP$ (Donate)

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, 10:16 AM   #5 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice


Quote:
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:
Quote:
<a href="tvguide_monday.php"><img src="image"></a>
(monday will change depending on the day...)
PoorDoggie is offline  
Old 05-15-2006, 12:01 PM   #6 (permalink)
NamePros Regular
 
cvxdes's Avatar
 
Join Date: Oct 2005
Location: Milford MA
Posts: 692
96.45 NP$ (Donate)

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


Quote:
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:
<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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 08:58 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85