JavaScript - Problem With Javascript Date Code
Problem with the Date when one date variable rolls back to a previous month.
Everything is explained he http://kcmaindomain.com/fix-js.html View Page Source of that page to see the java script code. I would greatly appreciate the help as I am fairly amateur coder and I have no idea how to correct this myself. Similar TutorialsI am trying to use JavaScript in conjuntion with html to display a table of sortable cities, states and dates. The dates are my problem. I am a novice and was given this code. But it seems to sort in European style, yyyy/mm/dd. I need it to sort mm/dd/yyy, which i am told is US style. Any help on this, I would be most grateful for. I have placed a page here to let you see the code at work. This page has the code on it in text also. I do not mind posting the code hgere also if you prefer. Thanks for any help you may be willing to offer me with this. Preston i've written a js function to find the difference between two dates. the format being used is dd/mm/yyyy hh:mm. The function returns correct value when give one set of values, but go wrong with another set. examples are given below. set 1 : Time 1 = 24/02/2011 09:30 , time 2 = 24/02/2011 16:00 Output is corret here. It gives 6 Hours & 30 Minutes (after converting the difference) set 2: Time 1 = 24/02/2011 09:30 , time 2 = 25/02/2011 16:00 Here, it gives 31 days, 6 Hours & 30 Minutes. My code is given below. Also the alert of dates display strange values. Don't know if it is timezone issue. I wonder what is going wrong here Code: function compareDateTime(frmtime,totime) { var date1 = new Date(frmtime); var date2 = new Date(totime); var diff = new Date(); alert(date1); alert(date2); diff = (date2.getTime()-date1.getTime()); if (diff<0) { alert("From Time cannot be later than To Time!"); return 0; } else if (diff==0) { alert("From Time cannot be equal with To Time!"); return 0; } else { return diff; } } The returned diff value is broken down as following: Code: if (diff>0) { days = Math.floor(diff / (1000 * 60 * 60 * 24)); diff -= days * (1000 * 60 * 60 * 24); hours = Math.floor(diff / (1000 * 60 * 60)); diff -= hours * (1000 * 60 * 60); mins = Math.floor(diff / (1000 * 60)); alert(days+","+hours+","+mins); return true; } Please Help... Not sure if this is possible in javascript: I'm looking for two different dates (bill date and due date) on an invoice that are captured by OCR. If one of them exists, but the other does not, I want the empty field to be 14 days before (or after) the other. For example: if the bill date is 7/27/2010 and the due date was not captured, I want to set the due date as 8/10/2010 (14 days after the bill date). If the due date was captured as 8/10/2010, but the due date is blank, I want to assign the bill date as 7/27/2010 (14 days before the due date). if both dates have values, do nothing. Thanks. Hello to everyone, . Im a new user and i have a question. Here is a code from a WebPage, in the page there is a button that called "Check Flaps" when i click it is need to run a javascript code and show me the results on the same window, but it not worked. The javascript code: Code: javascript:document.getElementsByTagName('html')[0].innerHTML.replace(/<!--|-->/g,'') Is Working only when i open a new window and copy & paste the code and hit enter. I want it to show me the results on the same window. Here is the method: Code: </ul> <div id="brakeline"></div> <div id="fs"> <form action="https://isp-012:qwerty123!!@cows-isp.hot.net.il/cgi-bin/cm_result.html?MAC=" name="frm2" method="get" id="cows" target="bottom"> <h5>#MAC</h5> <input class="textinput" type="text" name="MAC" id="MAC"> <div id="brakeline5"></div> <input class="submitc2" id="sumb" type="submit" value="Check"> </form> <form action="javascript:document.getElementsByTagName('html')[0].innerHTML.replace(/<!--|-->/g,'')" target="bottom"> <input class="submitc" id="ChkFlap" type="submit" value="Check Flaps"> </form> </div> Thanks. How to add 2 JavaScript code in 1 page so that, so that 1 jsp code could not affect another code?
Hello everyone, I am just beginning to learn javascript, and I am trying to create a little game where when a user hovers over a picture it changes, and things like that. At the moment I have been trying to make it so that the pictures tile so they fill the whole page area, dynamically so that it changes depending on the users browser size (px). The images have many attributes so I can't just tile them with css as they need to be actual elements. The problem is the code doesn't run, and I can't work out why. I think all the lines that require it have semi colons and its all correct. Forgive me if the answer is clear but as I said I only just started learning. Anyway, on with the code: Code: <!doctype html> <html lang="en"> <head> <title>Hi, I'm a button.</title> <link rel="stylesheet" type="text/css" href="style.css"> <script type="javascript"> function mainDo() { if (document.body && document.body.offsetWidth) { winW = document.body.offsetWidth; winH = document.body.offsetHeight; } if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth ) { winW = document.documentElement.offsetWidth; winH = document.documentElement.offsetHeight; } if (window.innerWidth && window.innerHeight) { winW = window.innerWidth; winH = window.innerHeight; } document.write('Width = ' + winW + 'Height = ' + winH); winW=winW/127; winH=winH/128; winW=Math.round(winW); winWs=winW; winH=Math.round(winH); winHs=winH; document.write('Width = ' + winW + 'Height = ' + winH); while (winH>0) { while (winW>0) { document.write('<img onMouseover="this.src=\'img/hibutton_orange.png\'" onClick="this.src=\'img/hibutton_green.png\'" ondblClick="this.src=\'img/hibutton_blue.png\'" src="img/hibutton_blue.png">'); winW=winW-1; } document.write('\n' + '<br>'); winW=winWs; winH=winH-1; } } </script> </head> <body onload="maindo()"> </body> </html> Hi, I have a code which i'm trying to make work. I need it so when I select the button it copies the code to the clipboard, then go directly to the site (eg: google.com), then I need the code to be pasted in to the browser bar and hit enter. I've been working on this for hours. I know i'm doing something wrong if someone could give me a simple code with these features then I could add in the stuff. This is the javascript that copies the code: Code: <script language="JavaScript"> var clip = null; function init() { clip = new ZeroClipboard.Client(); clip.setHandCursor( true ); clip.setText("*********CODE TO COPY IS HERE**********"); clip.glue('d_clip_button'); clip.addEventListener('complete', my_complete); setInterval(checkDone, 1000); } This is what I have to send them to the site. Code: <input type="button" value="Click Here" onClick="javascript:window.open('http://google.com');" > I don't know how to have it all in one so it copies the code then opens the site and pastes into the browser and enters. Regards, Andrew I have this script added to a facebook icon (#id) on my front page: (function() { var e = document.createElement('script'); e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; e.async = true; document.getElementById('fb-root').appendChild(e); })(); window.fbAsyncInit = function() { var fbClicked = false; FB.init({appId: 'Myappid', status: true, cookie: true, xfbml: true}); FB.Event.subscribe('auth.login', function(response) { if(response.session && fbClicked){ window.location = 'http://www.mysite.com/facebookauth/?ref=/'; } }); } function thFBShortCut() { FB.login(function(response) { fbClicked = true; if (response.session && response.perms && fbClicked) { window.location = 'http://www.mysite.com/facebookauth/?ref=/'; } }, {perms:'email,publish_stream'}); } function thFBLogin() { fbClicked = true; $('.popbox').fadeOut(); FB.getLoginStatus(function(response) { if(response.session && response.status == 'connected' && fbClicked) { window.location = 'http://www.mysite.com/facebookauth/?ref=/'; } }); } I want when whenever user press on facebook icon, the script should trigger facebook connect app. I added `<div id="fb-root"></div>` right after `<body <?php body_class(); ?>>`, but when I load my site I keep getting these error messages: document.getElementById("fb-root") is null and FB is not defined [Break On This Error] FB.login(function(response) { My html: <a id="facebookicon" onclick="thFBShortCut()">Login</a> 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 Im trying to make a code to work out how i am using the new Date commands Code: var Year = prompt('Enter the year you were born','19XX'); var Month = prompt('Enter the month you were born','January'); var Day = prompt('Enter the day you were born','1'); var birthDay = new Date(' ' +Month+ +Day+', '+Year); // birthDay var currentTime = new Date(); currentYear = (currentTime.getFullYear()); currentYear = (currentYear - Year); alert(currentYear); This is as far as i can get i want to get in to an excate age but i dont know where to start can someone give me a hand is there a way to compare the two dates birthDay and currentTime? Thanks Hi sir, I want to try use a javascript to display a code in this format....say May,wednesday 4, 2011 I have this code but it does not give me what i like Code: Code: <script type="text/javascript"> var currentTime=new Date() var day=currentTime.getDate() var month=currentTime.getMonth()+1 var year=currentTime.getFullYear() document.write("It is now "+day+"/"+month+"/"+year) </script> Please help me on a code like May,wednesday 4, 2011 Any help will be highly appreciated. Thanks Clement. Hello all.. I am new to the programming world and I need some help please. Working on a website for work and needing some Java assistance. I am working on this website. (Very simple) http://opc.deq.state.ms.us/aqi/aqi-msgulfcoastozone.htm and I am trying to set up coding to where the dates are updated daily. The only problem is, that I do not want the dates to update at Midnight Central time. Instead... I want the dates to update at 4pm Central Time (Since that is when I update my forecast) I am the states meteorologist... My 1st inclination is to manipulate the code to where the date would change 4pm Central time which would be midnight (+8 hours) Europe/Helsinki time. I am just unsure on how to manipulate the code to do so.. my current coding is. script type="text/javascript"> <!-- var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() + 1 var year = currentTime.getFullYear() currentTime.setDate(currentTime.getDate()+0); document.write(month + "/" + day + "/" + year) //--> </script> Any assistance would be greatly appreciated.. I wish I was more familiar w/ coding ... Wish I would have taken coding classes in college. Again much appreciated for reading/taking time to help me out. Hi, Please i have this code here which is not working to my expectation.Even though the code shows up the date alright but i want to add when it is morning should be AM whiles in evening PM. I have tried several ways to get it but i'm not.please help me to add a code to show PM when the time is (h>11) and AM when (h<11) .Here is what i did Code: <script type="text/javascript"> function runTime(){ var today=new Date(); var h=today.getHours(); var m=today.getMinutes(); var s=today.getSeconds(); if(m<10){ m="0"+m; } document.getElementById("text").innerHTML=h+":"+m+":"+s; t=setTimeout('runTime()',500); } if(h>11) { document.write("PM"); } else{ document.write("AM"); } </script> <body onload="runTime()"> <div id="text"></div> </body> Thank you. Clement Osei. Hello. I just want to check whether it is possible (and if so whether there is one available) to have a script that displays MY current time and date to visitors to my website. My time is Western European Time or Greenwich Mean Time. I would like visitors from eg Japan to see my local time and not their own. I think some date scripts I have seen use the user's local PC clock, but I am not sure? Thanks for any feedback and help! Hi, the source code on the website below i want to know what do i need to change to get the date to show as dd/mm/yyyy instead of mm/dd/yyyy? http://www.nsftools.com/tips/DatePickerTest.htm thanks for your help how can I get 1 tenth of a second for my clock? (bad typo for clock. I had to edit it. I'm saying that for the admin because I know you're not suppose to edit excessively)
hello i have this code: Code: Code: function buildMonthlyEntries() { var startDate = new Date(document.getElementById('startDate').value); var endDate = new Date(document.getElementById('endDate').value); if(startDate == "Invalid Date" || endDate == "Invalid Date") { return null; } var entryCount = endDate.getMonth() - startDate.getMonth(); var monthlyEntries = document.getElementById('monthlyEntries'); monthlyEntries.innerHTML = ""; for(var i = 0; i < entryCount; i++) { var textElement = document.createElement('input'); textElement.setAttribute('type', 'text'); textElement.setAttribute('id', 'entry' + i); monthlyEntries.appendChild(textElement); } return null; } <div id="dateRange"> <input type="text" id="startDate"> <input type="text" id="endDate"> </div> <div id="monthlyEntries"></div> <INPUT TYPE="button" NAME="button" Value="Click" onClick="buildMonthlyEntries()"> It calculates the number of months between the 2 dates and generates the number of input filds equal to the number of months. The only problem is when i change the year. For example if i have start date 2012-03-22 and enddate 2013-04-22, instead of generating 13 input fields it only generates 1 field, because it only substracts months. How can i make this script also calculate corectly months even if year is changed? Thanks I hope someone out there can help me! I am a librarian and am looking for a way to get javascript to display a simple future date for books we need to pull off our shelf. The date needs to be 6 days into the future. I want the date to display as either a hyphenated number: ie. 8-13 (for August 13th) or as an abbreviation of the month with the future date: ie. Aug. 13 I've tried this a number of ways, but I am just not getting the simple date format that I want. I need the script to automatically account for number of days in the month, etc. and adjust accordingly. For instance, if it was July 31st, I would want the script to display Aug. 6 or 8-6. I am not well-versed when it comes to javascript (read ignorant), but I posted below what I have managed to cobble together after searching online and playing with the ww3 school's "TryitEditor". Thanks for any help or tips in advance! Script below displays: PULL DATE: 6 days, on Saturday, August 13, 2011 Thanks! but I want it to display: PULL DATE: 6 days, on Aug. 13 or 6 days, on 8-13 Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en-GB"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>HOLD pull date</title> </head> <body> <form name="myFormName" method="get" action=" "> <h1>PULL DATE:</h1> <noscript><div>Javascript must be enabled in your browser</div></noscript> <script type="text/javascript"> var myDelayInDays=6; var myDate=new Date(); var oneDayInMilliseconds = (24*60*60*1000); var myTimeInMillisconds=myDate.getTime()+(myDelayInDays * oneDayInMilliseconds); myDate.setTime(myTimeInMillisconds); /* setTime() is an 'inbuilt' javascript function that calculates a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970 it can be buggy in some browsers */ var widgetDueDate = myDate.toLocaleDateString(); /* toLocaleDateString() is an 'inbuilt' javascript function that converts a Date object, according to local time, to a string and returns the date portion */ document.write('<p>' + myDelayInDays + ' days, on <strong>' + widgetDueDate + '<\/strong><\/p>'); </script> </form> <p>Thanks!</p> </body> </html> |