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(in Start, 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=docume nt.getElementBy Id(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(diff erence_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(incAbsB egan, 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.
2 2912 acoder 16,027
Recognized Expert Moderator MVP
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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()) # doesn't work!
you need to say
|
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 would be more orthogonal
if a method could only have one return statement.
--
|
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 are at least four ways to
do it.
For example if we have a method named M, that receives a reference to
parameter p and returns object o.
|
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 which I can get the duration
in days, hours and so.. but how can I get the difference in months?
Please reply ASAP. it's urgent.
--
regards,
Ashish Sheth
|
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 which
calculated the difference in years and days between two dates, and
takes leap years into account?
I'm calculating the difference in the usual way, i.e....
| |
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 object
- a variable (B) of the type "Type" which contains the type of the object in
(A) (A should be of the type B)
- a method which should return the object (A) as type (B)
|
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 this using actionscript via an 'onChange' event?
If so could anyone point me in the direction of an example or a tutorial that will help?
I hope you can help.
Regards
|
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 a way to convert a string like "1/2/2005" in a
genuan date object which is needed for calculation.
now once this is done I will create a another date object with
today = datetime.datetime.now()
and then see the difference between this today and...
|
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 temporary but it was stated that
it would not. This has come up in an irc channel but I can not find the
original thread, nor can I get any code to work.
Foo& Bar( int Val )
{
return Foo( Val );
}
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |