Can anyone alter this script for me so that it can have all 12 months in it and depending on which month, it displays that day? <script> <!-- var today_obj=new Date() var today_date=today_obj.getDate() var tips=new Array() tips[1]='Tip 1 goes here' tips[2]='Tip 2 goes here' tips[3]='Tip 3 goes here' tips[4]='Tip 4 goes here' tips[5]='Tip 5 goes here' tips[6]='Tip 6 goes here' tips[7]='Tip 7 goes here' tips[8]='Tip 8 goes here' tips[9]='Tip 9 goes here' tips[10]='Tip 10 goes here' tips[11]='Tip 11 goes here' tips[12]='Tip 12 goes here' tips[13]='Tip 13 goes here' tips[14]='Tip 14 goes here' tips[15]='Tip 15 goes here' tips[16]='Tip 16 goes here' tips[17]='Tip 17 goes here' tips[18]='Tip 18 goes here' tips[19]='Tip 19 goes here' tips[20]='Tip 20 goes here' tips[21]='Tip 21 goes here' tips[22]='Tip 22 goes here' tips[23]='Tip 23 goes here' tips[24]='Tip 24 goes here' tips[25]='Tip 25 goes here' tips[26]='Tip 26 goes here' tips[27]='Tip 27 goes here' tips[28]='Tip 28 goes here' tips[29]='Tip 29 goes here' tips[30]='Tip 30 goes here' tips[31]='Tip 31 goes here' document.write(tips[today_date]) //--> </script>
This script works fine for all months. On 1st of the month it will show the tip in tips[1] line and so on... Basically the message repeats only after 1 full month. Do you want to have 365 tips each for each day of year?
Can I butt in here? I would recommend taking the script down to the server - as the user shouldn't need to load and cache the tips for the months they're not using. And the javascript won't be giving your site the appearance of "fresh content" as it doesn't get indexed. The "tip of the day" is a good way to be slowly changing the content on your site - use it to it's fullest advantage. If you did it with PHP you'd echo $tips[date('d')]; PHP:
Im using the script to display an image of the day, not really for freshness or to show that its updated EVERY day to the visitor but to add some interactivity to the index page and intise visitors to look deeper into the site. Mainly using it as a preview. Thats a good idea about putting it on the server i will do that. What i need though is this script but 12 sets of the tips (12 months) and something in the script that determins the current month and then shows the tips that are under that month.
I posted this before but no one helped they just asked what i wanted then didnt tell me how to do it. I want the following script but with ALL 365 days in it. Currently there are 31 days in it and it repeats each month. I dont know how to alter it so that all 12 months are in it and not just 1. Im not good at javascript at all and was just wondering if anyone could set up what im looking for with it. <script> <!-- var today_obj=new Date() var today_date=today_obj.getDate() var tips=new Array() tips[1]='Tip 1 goes here' tips[2]='Tip 2 goes here' tips[3]='Tip 3 goes here' tips[4]='Tip 4 goes here' tips[5]='Tip 5 goes here' tips[6]='Tip 6 goes here' tips[7]='Tip 7 goes here' tips[8]='Tip 8 goes here' tips[9]='Tip 9 goes here' tips[10]='Tip 10 goes here' tips[11]='Tip 11 goes here' tips[12]='Tip 12 goes here' tips[13]='Tip 13 goes here' tips[14]='Tip 14 goes here' tips[15]='Tip 15 goes here' tips[16]='Tip 16 goes here' tips[17]='Tip 17 goes here' tips[18]='Tip 18 goes here' tips[19]='Tip 19 goes here' tips[20]='Tip 20 goes here' tips[21]='Tip 21 goes here' tips[22]='Tip 22 goes here' tips[23]='Tip 23 goes here' tips[24]='Tip 24 goes here' tips[25]='Tip 25 goes here' tips[26]='Tip 26 goes here' tips[27]='Tip 27 goes here' tips[28]='Tip 28 goes here' tips[29]='Tip 29 goes here' tips[30]='Tip 30 goes here' tips[31]='Tip 31 goes here' document.write(tips[today_date]) //--> </script>
I know absolutely nothing about javascript but I think this might work (it's probably NOT the best or most practical solution) <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function days_between(date1, date2) { // The number of milliseconds in one day var ONE_DAY = 1000 * 60 * 60 * 24 // Convert both dates to milliseconds var date1_ms = date1.getTime() var date2_ms = date2.getTime() // Calculate the difference in milliseconds var difference_ms = Math.abs(date1_ms - date2_ms) // Convert back to days and return return Math.round(difference_ms/ONE_DAY) } // End --> </script> </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin // Store the current date and time var current_date = new Date() // Store the date of the next New Year's Day var new_years_date = new Date() new_years_date.setYear(new_years_date.getFullYear() + 1) new_years_date.setMonth(0) new_years_date.setDate(1) // Call the days_between function var days_left = days_between(current_date, new_years_date) var day_number = Math.abs(365 - days_left) // it's up to you to add all those tips :p var tips = new Array() tips[1]='Tip 1 goes here' tips[2]='Tip 2 goes here' tips[3]='Tip 3 goes here' tips[4]='Tip 4 goes here' tips[186]='Tip 186 goes here' tips[187]='Tip 187 goes here' tips[188]='Tip 188 goes here' tips[189]='Tip 189 goes here' tips[190]='Tip 190 goes here' tips[191]='Tip 191 goes here' tips[192]='Tip 192 goes here' tips[193]='Tip 193 goes here' tips[194]='Tip 194 goes here' document.write (tips[day_number]) // End --> </script> </BODY> Code (markup): thanks to http://javascript.internet.com for the initial script. PS: I think it would be easier to just use a php file to show the appropriate tip ( it could get the tip from a text file or database)
Yes, 365 Tips A Tip For Every Day Of The Year. See Right Now The Script Only Holds 31... (1 Month) It Repeats Those 31 Tips Every Month. I Want The Script To Be Able To Hold 365 Tips So That There Are Different Tips Each Month. INSTEAD OF EACH MONTH BEING REPEATED IT WOULD BE EACH YEAR.
I cant get it to work on the first of the year... but works fine for this month. I dont know php and didnt know if i could put it on a .HTML page.