473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Return difference between two dates to another form object

I am trying to use javascript to calculate the difference between two form inputted dates and return the result to another form object. When I load up the page with the function on my web browser the form does not load and I get a message to say that the page contains errors, presumably as the function is not initialising or being referenced properly. Can anyone help, is the function scripted correctly and are the variables I am attempting to pass to the function referenced correctly?

I've manipulated a javascript function I found on the web until I arrived at the following:

function days_between(inStart, inEnd, outField) {

// Read values from the relevant form objects for start and end dates, and
// reference the output form object.
var sDate=document.getElementById(inStart).value;
var eDate=document.getElementById(inEnd).value;
var tmpField=document.getElementById(outField);

if (sDate != "" && eDate != "")
{// The number of milliseconds in one day
var ONE_DAY = 1000 * 60 * 60 * 24

// Convert both dates to milliseconds
var sDate_ms = sDate.getTime()
var eDate_ms = eDate.getTime()

// Calculate the difference in milliseconds
var difference_ms = Math.abs(eDate_ms - sDate_ms)

// Convert back to days and return
tmpField[0].value = Math.round(difference_ms/ONE_DAY)}
else
{tmpField[0].value = 0};
}

I am attempting to read the values in form objects 'inStart' and 'endStart', then if these values are not "" (empty) I am attempting to calculate the difference in whole days and return the result to form object 'outField' (denoted by 'tmpField' in the function).

Also, I call the function within a Flash form, within a coldfusion <cfinput> tag via the tag parameter onChange="days_between(incAbsBegan, incAbsEnded, incAbsShifts)", where 'incAbsBegan', 'incAbsEnded', 'incAbsShifts' are the names of the form objects for start date, end date and number of whole days between respectively.
Mar 23 '07 #1
2 2884
acoder
16,027 Expert Mod 8TB
Welcome to TSDN.

For this to work, you need to create a Date object. The value that you get from the form field is just a string. You need to convert that into a date and then call the getTime() method.

Date() object link.
Mar 23 '07 #2
dmjpro
2,476 2GB
if u have syntax error .. then the page will be loaded ... but no functions written in the js files ll run.

if u have the <body onload = fun_ref> then check out the coding of fun_ref .....

the best way to get the actual error ... u can use try catch block

have a good day ..... best of luck with ur code
Mar 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

47
by: Martin DeMello | last post by:
It seems to be a fairly common pattern for an object-modifying method to return None - however, this is often quite inconvenient. For instance def f(lst1, lst2): g((lst1 + lst2).reverse()) #...
94
by: John Bailo | last post by:
The c# *return* statement has been bothering me the past few months. I don't like the fact that you can have different code paths in a method and have multiple return statements. To me, it...
14
by: Gama Franco | last post by:
Hi, I'm designing an interface for a shared library, and I would like to know if there is a standard about how to return an object to the user. I will use exceptions to report errors, so there...
6
by: Ashish Sheth | last post by:
Hi All, In C#, How can I get the difference between two dates in number of months? I tried to use the Substract method of the DateTime class and it is giving me the difference in TimeSpan,From...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
9
by: Alexander Widera | last post by:
hi, is it possible to return an object of an unknown (but not really unknown) type with an method? i have the following situation: - a variable (A) of the type "object" which contains the...
1
by: Blackmore | last post by:
I'v got a flash form with two dates on it. I want the form to automatically display the difference between these two dates, when opened and if and when the dates are altered. Is it possible to do...
6
by: krishnakant Mane | last post by:
hello, I am strangely confused with a date calculation problem. the point is that I want to calculate difference in two dates in days. there are two aspects to this problem. firstly, I can't get...
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.