JavaScript - Change Text Based On Time Of Day
Hi Guys,
I am looking for a script to change text on a page based on the time of day. From 9am - 5pm weekdays I would like the page to display 'Open', and outside of that window to display 'Closed'. I am using HTML & PHP. Any help would be greatly appreciated. Thanks, Matt Similar TutorialsHello I am trying to do something similar to this post http://www.codingforums.com/showthread.php?t=168903 except I need it to be dependent on the hour and minute. Background: I am trying to create a schedule website, the schedule has say 20 items and I want it to display the current "active" event in the schedule, 1 previous event and 3 future events so a total of 5 items from the schedule. An event can range from 30 minutes to 2 hours long, so simply using the above code will not work. It needs to take the minutes into consideration as well. Let me know if you have additional questions. EDIT: 17-Mar-12 @ 12:37PM I would rather not use a bunch of if statements. (http://www.codingforums.com/showthread.php?t=250358) The schedule could change mid day so having to go through and edit a bunch of if statements would not be ideal Hi, what would be the best way to have a hidden array of possible text directed at a textarea and then if something is not within that array "onfocus", a certain select option is chosen within that form? Thanks hi, can some one help me how to get the time and date difference? given two time and date with the following format like in textbox A: 2011-05-03 17:35:47.0 and textbox B: 2011-05-03 16:35:47.0 then the output would be: 0 days, 1 hour, 0 minutes, 0 seconds regards, verve I have a site where users enter there certain timezome (+1, +4, -8 etc) and i want to display a clock with the local time on their profile page so when people view there profile they can see currently what time it is for them. I currently a have this. Code: function timeclock() { var t=setTimeout("startclock()",500); } function startclock() { var x = new Date(); var hour = x.getHours(); var min = x.getMinutes(); var sec = x.getSeconds(); if (hour<10){hour="0"+hour} if (min<10){min="0"+min} if (sec<10){sec="0"+sec} document.getElementById("clock").innerHTML=hour+":"+min+":"+sec; timeclock(); } Is it possible to alter the date dependent on the timezone? Maybe put startclock(timezone) andchange it to new Date(timezone);? I am looking to change a flash movie based on the time of day. Basicaly I need it to switch between a day/night version of the flash. I have this piece of code and want to know how to call the day.swf, night.swf in the flash object section where i have written 'WHAT DO I PUT HERE?' Any help with be greatly appreciated. Thanks. Code: <script type="text/javascript"> <!-- var DayOrNightMovie = "day.swf"; now = new Date(); hour = now.getHours(); if (hour > 6 && hour < 18) { DayOrNightMovie = "day.swf"; } else { DayOrNightMovie = "night.swf"; } var FlashObject = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="520" height="85" hspace="0" vspace="0" align="top">' FlashObject += '<param name="movie" value="WHAT DO I PUT HERE?"> <param name="quality" value="high"><param name="wmode" value="transparent">' FlashObject += '<embed src="WHAT DO I PUT HERE?" width="520" height="85" hspace="0" vspace="0" align="top" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></object>' document.write(FlashObject); // --> </script> Hello all. I have created a 2 frame site where I want the top frame (header) to redirect the other frame (main) to a different page depending on the date, time, and second. For example, on 12 FEB at 07:00:00, I would like the header frame to redirect the main frames page to EmmasBday.html; in which I would be alerted of my little sisters Birthday. This is for personal use and isn't going to be hosted online so I will just use JavaScript, it's basically a simple system to remind me of crucial events at certain times and dates so I don't forget them. The same events will apply every year, so there is no need to programme in specific years although having the option could prove useful. I am aware of other alternatives to achieve this, but would very much like to work with JavaScript; as I can expand it. As I state, this is for personal use and therefore won't be hosting it; I will use JavaScript throughout and cannot use anything else like PHP, Perl, etc. I am aware JavaScript takes the time & date from the computer hosting it (unlike PHP), which is fine. So, for example; at 14:30:00 I will be informed to get dinner; and at 15:00:45 I'll be informed to study. The knowledge you guys have presented so far is phenomenal, and I couldn't think of anybody better to ask for assistance. Anyway, I hope you can resolve my problem and I'm looking forward to a response! Thanks for your concern, you brain Gods you! AHa. Hey. I'm currently looking for a countdown script, which is based on the server's time. I've only found scripts, that's based on the local computer's time, which means the output of the script changes, when the time on the computer is changed. And I want to make a public announcement which counts down to something - and should output the same at every person. I'm not that familiar with JavaScript, I know some jQuery - if anyone can supply any links or can help me with this, I'd appreciate it. I am trying to change a character limit based on items changed in a drop down menu. To do this I have one function that will change the posted count based on the currently selected option and another function that is a commonly used char count with a few tweaks. The main issue is getting the value of the currently selected option. I know that selectedIndex will return the position of the selected element rather than the actual value. I tried to code around that. I've tried every method I could find on google and nothing works. So, I may have a bigger problem on a higher level that I just don't understand. If any of you can take a look at my code and give me your thoughts I would be most appreciative. Thanks! Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title></title> <script type="text/javascript"> function checkTextArea(fromto){ var textstring = "textarea"; var id = textstring + fromto; var destination = document.forms["form1"].[id.selectedIndex].text; if (destination=="1") { var limit = "500"; } else { var limit = "1000"; } if (document.getElementById(id)){ var txt = document.getElementById(id).value; if (txt.length>limit){ document.getElementById(id).value = txt.substr(0,limit); } len = document.getElementById(id).value.length; span_id = "span" + id; if (document.getElementById(span_id)){ document.getElementById(span_id).innerHTML = (limit-len); } // if } //if } //function function chardisplay(fromto) { var deststring = "dest"; var identifier = deststring + fromto; // no idea how to make this work...seems to stop working whenever I try to assign it to any kind of variable // I have also tried assigning .value and .text // I have also tried naming it with document.forms["form1"].[identifier.selectedIndex] // also using .value and .text var harmless = document.getElementById('identifier').selectedIndex; alert("value="+document.getElementById('identifier').value); alert("text="+document.getElementById('identifier').options.[harmless].text); var spanstring = "spantextarea"; var spanidentifier = spanstring + fromto; if (harmless=="1") { document.getElementById(spanidentifier).innerHTML = "500"; } else { document.getElementById(spanidentifier).innerHTML = "1000"; } } </script> </head> <body> <form id="form1" name="form1" method="POST" action="myurl"> <p><span id="spantextareafrSOMENUMBER">500</span> characters left </p> <select name="destfrSOMENUMBER" onchange="javascript:chardisplay('frSOMENUMBER');\" onfocusout="javascript:chardisplay('frSOMENUMBER');\" onblur="javascript:chardisplay('frSOMENUMBER');\"> <option value="opt1">display option 1</option> <option value="opt2">display option 2</option> <option value="opt3">display option 3</option> </select> <textarea onkeyup="checkTextArea('textareafrSOMENUMBER');" name="mesgfrSOMENUMBER" id="textareafrSOMENUMBER" cols=50 rows=4></textarea> </form> </table> </body> </html> Hello, I am trying to change the value of #name and #category inputs based on the value of select. A friend gave me the code below, but I can't get it to work. Thanks so much for your help Code: <script type="text/javascript"> $('#Gift_Type').change(function(){ if ($(this).val() == 'Monthly'){ $('#name').val('Partnership') $('#category').val('Partnership') } else { $('#name').val('Donation') $('#category').val('Donations') } }) </script> Code: <SELECT NAME="sub_frequency" ID="Gift_Type" onchange="OnSelectionChanged (this)"> <OPTION VALUE="1m">Monthly</OPTION> <OPTION VALUE="">One Time</OPTION> </SELECT> Code: <input type="text" id="name" name="name" value="Partnership" /> <input type="text" id="category" name="category" value="Partnership" /> I have a list of thumbnails generated by Wordpress. I've been trying to piece together a script that would change the ID of the parent element based on the image inside of it I can't seem to get anywhere, does anyone have a simple solution? I need the id of the li to be "sm" or "smp" depending on the width of the image inside of it (landscape or portrait) Code: <li class="frame" id="sm"> <div class="frm" id="frame1"> <img src="image.jpg"> </div> </li> I have a javascript controlling the display of a DIV that I did a while back that needs a bit more tweaking to add function to hide the DIV on specific holidays. As it is now, by default, the DIV is being hidden unless it is M-F between 8:00AM-6:00PM: Code: <script type="text/javascript"> onload=function(){ var rightNow = new Date(); var day = rightNow.getDay(); var hour = rightNow.getHours(); var minute = rightNow.getMinutes(); var formDisplay = 'none'; // unless we see otherwise var forwardDisplay = 'block'; // unless we see otherwise if(day==1 || day==2 || day==3 || day==4 || day==5) { // if chat is avalable on these days if((hour>=8) && (hour<=17)) // if chat is avalable between these times formDisplay = 'block', forwardDisplay = 'none'; } document.getElementById('ChatForm').style.display = formDisplay; document.getElementById('ChatForward').style.display = forwardDisplay; } </script> Im assuming that I would just add more else if statements, but not really sure the cleanest way to assign specific dates using this format. Any help is appreciated I'm trying to add a body class of 'day' if it's 6am-5pm and 'night' if it's 5pm-6am based on the user's local time. I tried the following but it didn't work. Any ideas? In the <head> Code: <script> function setTimesStyles() { var currentTime = new Date().getHours(); if(currentTime > 5 && currentTime < 17) { document.body.className = 'day'; } else { document.body.className = 'night'; } } </script> Code: <body onload="setTimeStyles();"> Also, is there a more elegant way to achieve what I need? Hi, I'm hoping this will be an easy one for you experts out there. I am working on a convention registration form. What I'm trying to do is have the text "50.00" pop into the COST field when any text (even if it's only one character) is entered into the NAME field. If the text in the NAME field is deleted, the "50.00" should also be deleted. Does anyone have a script that does this? Thanks! I'm new to coding and recently undertook the position as my school district's webmaster. We use a six day schedule where the days are labeled A-F. I want to be able to display the Today is...A graphic based on the date. I tried some scripts from other forums, but it does not appear to be working. Any suggestions? TY <code> <script language="javascript"> <!-- var picture=''; mytime=new Date(); mymonth=mytime.getMonth()+1; mydate=mytime.getDate(); if (mymonth==9 && mydate==13){picture="<img src=/images/d.gif>"; } if (mymonth==9 && mydate==14){picture="<img src=/images/e.gif width=150 height=150 alt=E>"; } if (mymonth==9 && mydate==15){picture="<img src=/images/f.gif width=150 height=150 alt=F>"; } if (mymonth==9 && mydate==16){picture="<img src=/images/A.gif width=150 height=150 alt=A>"; } if (mymonth==9 && mydate==19){picture="<img src=/images/B.gif width=150 height=150 alt=B>"; } if (mymonth==9 && mydate==20){picture="<img src=/images/c.gif width=150 height=150 alt=C>"; } //--> </script></code> Hi guys I have a little problem. I have 2 textfields and I need to change a link href based on whatever is in those textfields. The link has to be in this format: Code: <a class="display" href="test.php?test1=textfield1&test2=textfield2">test</a> The reason for this is I need to launch fancybox and as far as im aware this is the best way to call it. So what im hoping is when I add type something in textfield1 this will be reflected in the url. And same for textfield2. I know this can be done easily if I submit the page but I dont want that. Hopefully some javascript/ajax can help me out? I hope im being clear but let me know if im not. Thanks so much! thanks anyway
Hi All, I have a form that captures member registration details. In the admin section .. I would like to change the Status field of a record/s from NEW to PAYMENT DUE after 14 days from the data of submission. The status change should automatically trigger on the 15th day. So when the admin checks the list page he/she should be able to view the updated status field. Any pointers how to accomplish this? Thanks in advance. Vinny Hello, I just joined the forum. I'm hoping someone could help me out or point me in the right direction. I am trying to set up a simple interaction for users. The user would be required to select a width then height from two separate drop down menus. I used this as an example to work from: http://www.w3.org/TR/WCAG20-TECHS/wo...dynselect.html The list of heights would not be available until the user selects a width.(similar to the example link above). Each width would have slightly different heights associated with it. After the user selects a width then height an image would be displayed based on that combination. So for example if the user selects 12w/30h they would see "01.jpg" if the user selects 12w/36h they would see "02.jpg". This would all be done on the same page. The user should be able to update the image by combining the different width/height options indefinitely. If anyone has a link to an example or can provide a basic structure I could build of off I would be extremely grateful, thanks. Hi there, Where I work there are certain dates where nothing can be done, certain times where work can be done with caution, and dates where work can be done. I want to put on the site a traffic light that would change colours based on the calendar dates where work can/can't be done. For example, if April 11th there is stuff to do, the traffic light would be green. But April 12th, there isn't work to do, it would turn red. Do you know how I would go about doing this? I don't know if this is possible, so I figured I'd ask a few gurus. I know it is possible to have an image change at a certain time of day, and it's also possible to have an image change by day, but is there a script to do both? What I want to do is have the first image show from 8am cst to 6pm cst mon-fri, it's our open sign for live chat. The the rest of the time have the second image. Is this possible with any type of script? Any help you can give is greatly appreciated! |