| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| NamePros Member | 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 |
| |
| | #3 (permalink) |
| NamePros Regular | 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;
|
| |
| | #4 (permalink) |
| NamePros Member | 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 |
| |
| | #5 (permalink) | ||
| Soon to be RICHdoggie! | Quote:
)here is an even nicer script: (put this where you want the link displayed) PHP Code: Quote:
| ||
| |
| | #6 (permalink) | |
| NamePros Regular | Quote:
<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();' | |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |