JavaScript - Grouping Getmonth And Getdate
I'm trying to make it so that on holidays, my page will say Happy"so and so..." at the top. I only started this 5 minutes ago so that's why it's so under developed. Here's what I have. I'm wanting to know if "today.getMonth.getDate" is valid or would I have to do something else.
function startTime() { var today=new Date(); var hol=today.getMonth.getDate() if (hol==4+1) p.s I only want the holiday. I already have a clock but I want them to be separate. Similar TutorialsHi all, I've got this working perfectly in FF, I have some code that gets the month of a date object, and it doesn't work in IE and it doesn't make sense why... Code: var date = cdr.c[id].date; var month = date.getMonth(); But .getMonth() returns NaN... It is a valid date object as it works perfectly in FF. If you need more code just ask! i am making a hire script for my website, we have a summer and a winter rate for hires over 28 days, so if the month is between march and September its one price ( sting 9) and if its not then its sting 8. please can someone help Code: function calculate() { var days = parseInt('0' + document.date.days.value, 10), groupstring, total = 0; <!-- 1 day, 2 days, 3 days, 4 days, 5 days, 6 days, 7 days, 28 DaySummer, 28 DayWinter, Excess Amount, excess miles................................. --> switch (document.date.car.value) { case 'A': groupstring = '2500,5000,7500,10000,12500,12800,13000,45000,42000,25000,10'; break;<!--PANDA/SAMRT --> case 'B': groupstring = '2650,5300,7950,10600,13250,13500,14500,48000,46000,25000,10'; break;<!--CLIO 3/5/MAN PIC --> case 'CD': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10'; break;<!-- RIO CLIO T PIC AUTO--> case 'E': groupstring = '3000,6000,9000,12000,15000,15500,16500,53500,51000,25000,10'; break;<!-- VENGA RIO AUTO--> case 'F': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15'; break;<!-- FOCUS/MEGANE/CEED--> case 'G': groupstring = '3500,7000,10500,14000,17500,19000,20000,62000,59000,25000,15'; break;<!--ESTATE --> case 'H': groupstring = '3800,7600,11400,15200,19000,21500,22500,72000,62000,25000,15'; break;<!-- -MONDEO-> case 'I': groupstring = '4500,8000,12000,16000,20000,24000,25000,75000,65000,40000,15'; break;<!--2WD SPORTAGE --> case 'J': groupstring = '5000,9000,13500,18000,22500,26000,27000,80000,80000,40000,15'; break;<!--4WD SPORTAGE --> case 'K': groupstring = '6500,11000,16500,22000,27500,30000,31000,950000,82500,40000,15'; break;<!--GLA + RCZ --> case 'L': groupstring = '7000,12000,18000,24000,30000,35000,360000,120000,1200000,25000,15'; break;<!-- SORENTO--> case 'M': groupstring = '2650,5300,7950,10600,13250,14600,15000,49900,48000,25000,10'; break;<!-- KANGOO--> case 'O': groupstring = '4100,8200,12300,16400,20500,20800,21000,75000,72500,40000,15'; break;<!-- TRAFIC--> } groupstring = groupstring.split(','); m = new Date (document.date.firstDate.value); month = m.getMonth(); if (days > 0 && days < 8) {total = groupstring[days - 1]; } else if (days < 28) {total = (groupstring[6] / 7) * days;} else if (days === 28) {total = groupstring[8];} if (days > 28) {total = (groupstring[8] / 28) * days;} if (month > 3 < 8 && day ==28) {total = (groupstring[9];} I'm trying to get the day of the week to show up as a number on the page. The problem is, no matter what I try, it's coming back as 4. I made this alert to test the code. This alert works UNLESS anything else is ordered before +monthBirth. If the order is changed it adds it together which I guess is because of the plus. Code: alert(+monthBirth +dateBirth +yearBirth) What I want is the day of the week to show up as a number on the page. I think the reason I keep getting 4 is due to something with the addition problem I have? But I really have no idea at all. Can anyone please help? Code: <html> <head> <script> MONTHS_OF_THE_YEAR = 'janfebmaraprmayjunjulaugsepoctnovdec'; MILLISECONDS_DAY = 1000*60*60*24; MILLISECONDS_YEAR = 1000*60*60*24*365.2424; LIFE_EXPECTANCY = 1000*60*60*24*365.2424*67.2; var daysArray = new Array ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); var yearBirth = ''; yearBirth = prompt('Please enter your year of birth'); var monthBirth = ''; monthBirth = prompt('Please enter your month of birth'); monthBirth = monthBirth.slice(0,3); monthBirth = monthBirth.toLowerCase(); monthBirth = MONTHS_OF_THE_YEAR.indexOf(''+monthBirth)/3; var dateBirth = ''; dateBirth = prompt('Please enter your date of birth'); alert(+monthBirth +dateBirth +yearBirth) var dd=new Date(+monthBirth); dd=dd.getDay(); document.write(dd); </script> </head> <body> </body> <html> I'm new to java and have been given the following piece of code to try and fix. The code is renaming an existing HTML file with the current date but the problem is the date is out by one. I'm aware that in java Jan=0 Feb=1 etc but just dont know enough to know how to fix this... If I add +1 to getmonth all that happens is the file gets named LEICESTER_DAILY - 24-71-2011 17.20.36 rather than LEICESTER_DAILY - 24-8-2011 17.20.36 Here's the piece of code Code: function makePerm() { var txtFile; // Swap the temporary file with the original if (fileSys.FileExists(grabParentFolderUrl() + 'tempsave.htm')) { txtFile = fileSys.getFile(grabParentFolderUrl() + 'tempsave.htm'); if (!(txtFile.size == 0)) { // Check file is not empty if (fileSys.FileExists(grabParentFolderUrl() + 'LEICESTER_DAILY.htm')) { var today = new Date(); var timeStamp = today.getDate() + '-' + today.getMonth() + '-' + today.getFullYear() + ' ' + today.getHours() + '.' + today.getMinutes() + '.' + today.getSeconds(); txtFile = fileSys.getFile(grabParentFolderUrl() + 'LEICESTER_DAILY.htm'); txtFile.Move(grabParentFolderUrl() + 'LEICESTER_DAILY - ' + timeStamp.toString() + '.htm'); txtFile = fileSys.getFile(grabParentFolderUrl() + 'tempsave.htm'); txtFile.Move(grabParentFolderUrl() + 'LEICESTER_DAILY.htm'); Okay, I've posted the code with just the two fields needed to solve my problem. If I type in a date of 04/16/2011 in the "sentence date" field, then click the calculate button, the date 03/05/2011 is displayed in the "Due to Reviewer" field. It subtracts 42 days from the date enetred into the "Sentence Date" field. My problem is, sometimes when I type in a date in the "Sentence Date", such as 04/16/2011, 42 days prior falls on a weekend & I need it to always be on a weekday. So with that said, is it possible to put some type on function in the code where if the date falls on a weekend (Saturday or Sunday), it will roll back & display Friday's date? Thanks again for the help! <html> <head> <script type="text/javascript"> var valid; function d2(v) { return (v<10)?("0"+v):v; } function dcheck(form) { var s = form.sent_date.value; var sent = new Date(s); var dr = form.due_rev.value var due_rev = new Date(dr); if (isNaN(due_rev)) { due_rev = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-42); } form.sent_date.value = (sent.getFullYear()+0) + "-" + d2(sent.getMonth()+1) + "-" + d2(sent.getDate()); form.due_rev.value = (due_rev.getFullYear()+0) + "-" + d2(due_rev.getMonth()+1) + "-" + d2(due_rev.getDate()); return true; } </script> </head> <body> <form method="post" action="add.php"> </select> </br> <b>Sentence Date: MM/DD/YYYY</b> <br /> <input type="text" name="sent_date" size="30" /><br /> <p><input type="button" value="Calculate" onclick="return dcheck(this.form);"> </p> <b>Due to Reviewer:</b> <br /> <input type="text" name="due_rev" size="30" /><br /> <br> </form> </body> </html> Hi all, I have a form with multiple Divs containing radios, text etc. What I'm trying to do is write a function that will validate all radios only within a specified Div (in the code example below, Div4). I need to validate if all the radios in the div have "no" selected, or button[1]. If any have yes selected, then nothing happens. Only if all have No selected do I need something to happen. Assigning radios to groups for validation is something I've done on a global (all of form) scale, but I can't figure how to be explicit to a div. The code below works, but only on individual radios, not groups. I've included a few buttons outside the div for effect. Oh, and the final product won't have alerts, it will be used to trigger a hidden div elsewhere in the form. Any help or pointers would be greatly appreciated. Code: <html> <head> <title>Test</title> <script type="text/javascript"> function radCheck(){ var d = document.getElementById("Div4"); var list = d.getElementsByTagName("input"); for (var i = 0; i < list.length; i++){ var node = list[i]; if (node.getAttribute('type') == 'radio'){ if (node.checked == false){ alert("something bad"); } else{ alert("something good"); } } } } </script> </head> <body> <form name="radiotest" action=""> <div id="Div4"> <input type="radio" name="radReason1" id="R1" value="Yes"><label for="R1">Yes</label> <input type="radio" name="radReason1" id="R2" value="No"><label for="R2">No</label><br><br> <input type="radio" name="radReason2" id="R3" value="Yes"><label for="R3">Yes</label> <input type="radio" name="radReason2" id="R4" value="No"><label for="R4">No</label><br><br> <input type="radio" name="radReason3" id="R5" value="Yes"><label for="R5">Yes</label> <input type="radio" name="radReason3" id="R6" value="No"><label for="R6">No</label><br><br> <input type="radio" name="radReason4" id="R7" value="Yes"><label for="R7">Yes</label> <input type="radio" name="radReason4" id="R8" value="No"><label for="R8">No</label><br><br> </div> <input type="radio" name="radReason5" id="R9" value="Yes"><label for="R9">Yes</label> <input type="radio" name="radReason5" id="R10" value="No"><label for="R10">No</label><br><br> <input type="radio" name="radReason6" id="R11" value="Yes"><label for="R11">Yes</label> <input type="radio" name="radReason6" id="R12" value="No"><label for="R12">No</label><br><br> <input type="button" value="Check" onclick="javascript:radCheck();"><br> </body> </html> |