JavaScript - Dynamic Images Based On Date - Hours Of Operations
Hello,
I've been trying to figure this script out for awhile and I've hit a wall. Basically, what I want to do for my organization's website is to use JS to display an image containing our hours and have it change each day of the week. The hard part (for me) is that there are certain days we're closed. Ideally, I'd like a separate "We're Closed" message to overwrite the image carrying our hours on specific days (major holidays like Xmas, New Years, Vet's Day, furlough periods, etc. etc.). Here's the code I've managed to cobble together (I have a real basic understanding of JS, so I've been pulling scripts from sites offering free copy/pastecode): [CODE] <script language="javascript"> mytime=new Date(); mymonth=mytime.getMonth()+1; mydate=mytime.getDate(); myday=mytime.getDay(); arday = new Array("sunday.png", "monday.png", "tuesday.png", "wednesday.png", "thursday.png", "friday.png", "saturday.png"); document.write("<img src='" + arday[myday] + "'>"); if (mymonth==12 && mydate==24){document.write("<img src='closure.png'>"); } </script> [CODE] For the most part, this code works just fine. However, if I jump my system clock to December 24, the "closure.png" comes up appears ALONGSIDE the hours image for that day of the week. In other words, I've got two images appearing right next to each other - that's not what I want. How can I work the code in such a way that when a closure date comes up (in this case, 12/24), just the "closure.png" image shows up by itself? Thank you all so much for your time and patience. Similar TutorialsJavascript novice here looking to create a dynamic dropdown based on date. It's a list of preset prices that will change each month to reflect a pro-rated system. Any thoughts/examples on how I would go about setting this up using javascript would be much appreciated. Thanks. Here's what I need: In September, the dropdown will display these prices Code: <option value="100">Product 1</option> <option value="150">Product 2</option> <option value="200">Product 3</option> In October, the dropdown will display these prices <option value="50">Product 1</option> <option value="100">Product 2</option> <option value="150">Product 3</option> Hello 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 guys, I've looked around the web and tried to find a Javascript Countdown, however, the only ones I could really find were the ones that countdown to a particular date (see below). Code: <script language="JavaScript"> TargetDate = "12/31/2020 5:00 AM"; BackColor = "palegreen"; ForeColor = "navy"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds."; FinishMessage = "It is finally here!"; </script> <script language="JavaScript" src="/js/countdown.js"></script> Problem is, it counts down to a particular date, and I don't want that. The reason why is because everyone's time will be different, and I want it to be a "global" countdown, fr an event happening on a website (like the launch of something). Is it possible to, other then going by date, go by days/hours/minutes/seconds? So if I enter say, 2 days, 5 hours, 0 minutes, 0 seconds, it'll start counting down EXACTLY 2 days and 5 hours, and not change per people's time zone? Any help would be greatly appreciated. If someone can point me in the right direction, or has a code already developed, I'd really appreciate it.. Thank you so much! I have a drop down menu where people can select a month, day and year. Based on their selection, I want to show them an image. If their selection is >= July 26, 2010 but <= July 25, 2011, show the red image; If their selection is >= July 26, 2011 but <= July 25, 2012, show the white image; If their selection is >= July 26, 2012 but <= July 25, 2013, show the blue image; If their selection is >= July 26, 2013 but <= July 25, 2014, show the yellow image; I don't know how to compare a selected date to a range of dates like this. Hi folks, i am trying to generate a dynamic datefield with date mask "mm/dd/yyyy" and trying to insert it into Oracle db ...i still got the error ORA invalid month ehich means the date filed is not recognized as date: below is what i am doing : newStartDate = document.createElement( 'INPUT' ); newStartDate.setAttribute('type','Date'); newStartDate.setAttribute('id1','id'+ elementid+elementrow); newStartDate.setAttribute('name','StartDateName'+ elementid+elementrow); newStartDate.size=8; newStartDate.style.backgroundColor= bgc; any help thanks ?? Also i want to add a datepicke to this textbox..how it is posible / other option is to use Jquery datepicker but could not know how to impement it thanks again Hello, I'm new here and also new to writing JS. I was hoping someone could tell me what is wrong with the code below. I am trying to load a page, and the filename will be different depending on current month and year. If I use the code below in the body for document.write instead of window.location it correctly displays this months page as 102009.htm. Is there a better way to do this? Thanks in advance for any help. Code: <script type="text/javascript"> <!-- var months=new Array(13); months[1]="01" months[2]="02" months[3]="03" months[4]="04" months[5]="05" months[6]="06" months[7]="07" months[8]="08" months[9]="09" months[10]="10" months[11]="11" months[12]="12" var time=new Date(); var lmonth=months[time.getMonth() + 1]; var year=time.getYear(); window.location = (1month + year + ".htm") //--> </script> I have a form that has a pretty complicated combo box - a user starts typing text, it queries a database for matches, and displays the results to the user. The user can then select the match they desire and it has a value id, which I am currently sending to a hidden field in the form. So, for example: user starts typing in a movie name, Seven - it returns Seven and user selects it. The form submits the id of the movie seven (say 12) to a hidden field. Where I am stumped: Once a user selects a movie title, I have another drop down select box that is to display the available formats of the movie by querying my database based on the product id (12) and returning the available formats in the list: DVD BLUERAY VHS I am pretty good at programming, but I cannot figure this out - how to make the select box fire and return results once the value for the textbox has been captured. Can anyone help me? Hi, I have 3 selects in a form for day, month and year for the user to enter his/her birthday. What I'm looking for is a piece of code / script which will dynamically change the day dropdown menu dependent on the month which is selected to display the correct number of days, and also according to if it is a leap year. Ive tried looking on google but I'm not sure what the correct term is to look for? Could anyone please help? Thanks 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. I have this script that I got from some site. When you click on a link tied to a div it hides all other divs and displays just that one. Well, that works, but I want it to display one of the divs on page load based on today's date. For example, it will display the "summer" div if today's date is anywhere between June 1 and August 31. When links to other divs are clicked that div will disappear and other ones will appear in its place. Anyway, here's the code, and I don't know anything about javascript so I have no idea where to even start editing it. Please help Code: <script type="text/javascript"> <!-- Layer Show/Hide Script last="" function changeDiv(the_div,the_change) { var the_style = getStyleObject(the_div); if (the_style != false) { the_style.display = "block" if(last!="") { last.display = "none" } } last=the_style } function getStyleObject(objectId) { if (document.getElementById && document.getElementById(objectId)) { return document.getElementById(objectId).style; } else if (document.all && document.all(objectId)) { return document.all(objectId).style; } else { return false; } } //--> </script> Hi guys. I am kind of new to javascript, and was hoping that someone here could help out on a problem I have been having. What I am trying to do is to make a page which will redirect to three diffrent sites, based on date. I want it to change to diffrent sites during the time before summer to summer, the time before xmas till xmas and from before easter till easter. A bit more spesific this would be: From 29. march --> 22. july (summer) From 22. august --> 24. december (xmas) From 3. january --> 22. march (easter) Could you help me out? I have tried lots of diffrent ways to do this with javascripts if...else statements, but I havent yet found a way to make it work properly. Really thankful for answers! Hi All, i am having some difficulties to figure out how can i link get my calendar (datepicker) working with my dynamic generated textbox . I am using a Jquery file that i download form the net <!-- link calendar files --> <script language="JavaScript" src="calendar_us.js"></script> <link rel="stylesheet" href="calendar.css"> and here is my code to generate my dynamic controls which is working fine actually..i need to have : 1- option : the datepicker showing up once i click on StartDate textbox 2- in the future i ll use an img and i want to use it to populate the datepicker. below is my modest javascipt code i use to create dynamic textbox: <script type="text/javascript"> // Declare element id for different dynamic generated controls var elementid = 1; function addNew() { var elementrow = 1; // Get the main Div in which all the other divs will be added var mainContainer = document.getElementById('mainContainer'); // Create a new div for holding text and button input elements var newDiv = document.createElement('div'); var bgc ="##E2E2E2"; //"##b2d47e"; newStartDate = document.createElement( 'INPUT' ); newStartDate.id = 'id' + elementid + elementrow; newStartDate.setAttribute('id1','id'+ elementid+elementrow); newStartDate.setAttribute('name','StartDateName'+ elementid+elementrow); newStartDate.size=8; newStartDate.style.backgroundColor= bgc; // Create buttons for creating and removing inputs var newAddButton = document.createElement('input'); newAddButton.type = "button"; newAddButton.value = " + "; newAddButton.title = " Add new Project"; var newDelButton = document.createElement('input'); newDelButton.type = "button"; newDelButton.value = " - "; newDelButton.title = " Remove Project"; // Append new text input to the newDiv newDiv.appendChild(newStartDate); // Append new button inputs to the newDiv newDiv.appendChild(newAddButton); newDiv.appendChild(newDelButton); // Append newDiv input to the mainContainer div mainContainer.appendChild(newDiv); // Add a handler to button for deleting the newDiv from the mainContainer newAddButton.onclick = addNew; newDelButton.onclick = function() {mainContainer.removeChild(newDiv);}; elementid++; } </script> any help will be apprecited ! 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 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 I have wrote a code for some calculation that checks whether the RUN_time of an application falls between the Start_time and Stop_time, If it falls between the Start_time and Stop_time, then an alert with Success Message should popup else failure alert should popup. I dont know what's the problem with the code, its not displaying the correct alert. Can some experts deal with this and correct the code. Code: <html> <head> <script type="text/javascript"> function convert12to24(timeStr) { var meridian = timeStr.substr(timeStr.length-2).toLowerCase(); var hours = timeStr.substring(0, timeStr.indexOf(':')); var minutes = timeStr.substring(timeStr.indexOf(':')+1); return hours+':'+minutes; } //This function only for testing function changeTimeFormat() { var input = document.getElementById('input').value var twenny4hr = convert12to24(input); //document.getElementById('output').value = twenny4hr; var input_hr = twenny4hr.substring(0, twenny4hr.indexOf(':')); var input_min = twenny4hr.substring(twenny4hr.indexOf(':')+1); if(input_hr >= 24) { alert('Hours should fall between 0:00 to 23:59'); softclose.input.value=''; } if(input_min > 59) { alert('Minutes should fall between 00 to 59'); softclose.input.value=''; } if(input_hr == 12) { var twelvehr = parseInt(input_hr); document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'P.M.'; } else if(input_hr > 12 ) { var twelvehr = parseInt(input_hr)-12; document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'P.M.'; } else if(input_hr == 12 && input_hr == 0 || input_hr == 00 ) { var twelvehr = parseInt(input_hr) + 12; document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'A.M.'; } else { var twelvehr = parseInt(input_hr); document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'A.M.'; } } function changeTimeFormat1() { var t_bus_clndr_gmt = document.getElementById('t_bus_clndr_gmt').value var twenny4hr = convert12to24(t_bus_clndr_gmt); //document.getElementById('output1').value = twenny4hr; var t_bus_clndr_gmt_hr = twenny4hr.substring(0, twenny4hr.indexOf(':')); var t_bus_clndr_gmt_min = twenny4hr.substring(twenny4hr.indexOf(':')+1); if(t_bus_clndr_gmt_hr >= 24) { alert('Hours should fall between 0:00 to 23:59'); softclose.t_bus_clndr_gmt.value=''; } if(t_bus_clndr_gmt_min > 59) { alert('Minutes should fall between 00 to 59'); softclose.t_bus_clndr_gmt.value=''; } if(t_bus_clndr_gmt_hr == 12) { var twelvehr = parseInt(t_bus_clndr_gmt_hr); document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'P.M.'; } else if(t_bus_clndr_gmt_hr > 12 ) { var twelvehr = parseInt(t_bus_clndr_gmt_hr)-12; document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'P.M.'; } else if(t_bus_clndr_gmt_hr == 12 && t_bus_clndr_gmt_hr == 0 || t_bus_clndr_gmt_hr == 00 ) { var twelvehr = parseInt(t_bus_clndr_gmt_hr) + 12; document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'A.M.'; } else { var twelvehr = parseInt(t_bus_clndr_gmt_hr); document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'A.M.'; } //EST Format var min = twenny4hr.substring(twenny4hr.indexOf(':')+1); var esthour = parseInt(twenny4hr)-4; if(esthour > 12) { document.getElementById('EST').value = esthour + ':' + parseInt(min); } else if(esthour < 0) { document.getElementById('EST').value = esthour + 12 + ':' + parseInt(min); } else { document.getElementById('EST').value = esthour + ':' + parseInt(min); } } function open_close_window() { var est = document.getElementById('EST').value; var min = est.substring(est.indexOf(':')+1); var ow = document.getElementById('open_window').value; var cw = document.getElementById('close_window').value; var est_hour = est.substring(0, est.indexOf(':')); var start_time = parseInt(est_hour - ow); var stop_time = parseInt(est_hour) + parseInt(cw); document.getElementById('start_t').value = start_time + ':' + parseInt(min); document.getElementById('end_t').value = stop_time + ':' + parseInt(min); } function check1() { var user_req_time = document.getElementById('input').value; var user_req_hours = user_req_time.substring(0, user_req_time.indexOf(':')); var start_time1 = document.getElementById('start_t').value; var start_hours = start_time1.substring(0, start_time1.indexOf(':')); var stop_time1 = document.getElementById('end_t').value; var stop_hours = stop_time1.substring(0, stop_time1.indexOf(':')); if(start_hours < user_req_hours ) { flag = 0; } else { flag=1; } if(stop_hours > user_req_hours) { flag1 = 0; } else { flag1=1; } if(flag == 0 && flag1 ==0) { alert('success'); } else { alert('failure'); } } </script> </head> <body> <form name="softclose"> <table> <tr> <td> User Requirement [24 hr format] : </td> <td> <input type="text" name="input" id="input" onkeyup="changeTimeFormat();"> EST </td> <td> 12Hr Output : </td><td> <input type="text" name="output" id="output"></td> </tr> <tr> <td> TBUS_CLNDR DB Time [24 hr format] : </td> <td><input type="text" name="t_bus_clndr_gmt" id="t_bus_clndr_gmt" onkeyup="changeTimeFormat1();"> GMT </td> <td> 12Hr Output : </td> <td><input type="text" name="output1" id="output1"> </td> </tr> <tr> <td width=200> Open Window </td> <td width=120 colspan=2><input type='text' name="open_window" id='open_window' size=5 onkeyup="open_close_window();"//> Hrs </td> </tr> <tr> <td width=200> Close Window </td> <td width=120 colspan=2><input type='text' name="close_window" id='close_window' size=5 onkeyup="open_close_window();"/> Hrs </td> </tr> </table> <br><br><br> <table> <tr> <td width=200> EST Format: </td> <td ><input type="text" name="EST" id="EST" value="" > EST</td> </tr> <tr> <td width=200> Start Time: [24 hr format]</td> <td ><input type="text" name="start_t" id="start_t" value="" ></td> </tr> <tr> <td width=200> End Time: [24 hr format]</td> <td><input type="text" name="end_t" id="end_t" value="" ></td> </tr> <tr> <td align=center> <input type=button name=check id=check value=check onclick="check1();"> </td> </tr> <table> </form> </body> </html> Is it possible to have one of nine elements of an array, each containing code that will fill in a square in a tic-tac-toe game, randomly chosen then the code executed? If not, can anyone explain why and/or another way to do it? I have a javascript that loads images on the page based on the date you select from a drop down menu. So the images are displayed dynamically, however they are numbered 1 through 20. Is there a way I can add a title tag to the images that will display on mouseover? Here's the page I am working on. I want to add title tags to the six images on the right side of the page. They change based on the date selected. webpage Thanks. Hi, how would i edit the code below so instead of today is day 16 of the month to an actual date eg Today is 10/11/2011 (dd/mm/yyyy or mm/dd/yyyy compatible). I need the code to execute on a specific date. javascript or php versions very welcome THANKS Code: <script type="text/javascript"> var Date = new Date(); var Today = Date.getDate(); if(Today == 16) { document.write('<img src="http://www.imagelocation_here" alt="Image title " width="117" height="100" />'); } else { document.write('<img src="http://www.imagelocation_here" alt="image title " width="117" height="100" />'); } </script> |