Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>Simple mathematicall formula???

Simple mathematicall formula???

njwoods
03-17-2006, 02:30 PM
I have just begun learning javascript and could use some real help. I am looking for a way to subtract two "times", for use in an Acrobat form.

e.g: (11:00-08:00)+(21:45-11:30)+(23:00-21:45)=total time

OR (in field names)

(time2-time1)+(time4-time3)=totaltime1


any assistance is greatly appreciated

liorean
03-17-2006, 02:38 PM
You could use the Date object for it. See <uri:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Date> for data about that.

swtrans
03-17-2006, 03:02 PM
I'm glad njwoods asked this question. Was just about to ask about time differences and there was a good example in the link from liorean.

I'm having problems using a function to update the time. Am I missing something simple or does this have to do with the date/time requirements?

--------------------------------------------

<script type="text/javascript">

var timeA = new Date();
var timeB = new Date();
var timeDif = timeB - timeA;

function UpdateTimeB(){
timeB = new Date();
}

</script>

<input type="button" value="timeA" onclick="alert(timeA)"><br><br>
<input type="button" value="timeB" onclick="alert(timeB)"><br><br>
<input type="button" value="timeDif" onclick="alert(timeDif)"><br><br>
<input type="button" value="UpdateTimeB" onclick="updateTimeB()"><br><br>

liorean
03-17-2006, 03:11 PM
swtrans:
You did the timeDif=timeB-timeA part once, with the original values for timeA and timeB. You never after that update timeDif, so it will stay the same. Only timeB will be updated.

swtrans
03-17-2006, 04:38 PM
liorean see what you mean. I added an update to that, but for some reason I keep getting an error when I push the update button.

<script type="text/javascript">

var timeA = new Date();
var timeB = new Date();
var timeDif = timeB - timeA;

function UpdateTimeB(){
timeB = new Date();
timeDif = timeB - timeA;
}

</script>

<input type="button" value="timeA" onclick="alert(timeA)"><br><br>
<input type="button" value="timeB" onclick="alert(timeB)"><br><br>
<input type="button" value="timeDif" onclick="alert(timeDif)"><br><br>
<input type="button" value="UpdateTimeB" onclick="updateTimeB()"><br><br>

swtrans
03-17-2006, 04:40 PM
I see the problem:

onclick="updateTimeB()"

case sensative

onclick="UpdateTimeB()"><


 

TOP

Hyperthreading hurts s
HP sharpens blade PC l
Apple goes for Quad po
Itanium gets scaled do

For more info

HP sharpens blade PC l
Hyperthreading hurts s
can not call click() i
script does not work o
smart menu 
write to an html file 
FireFox doesn't recogn
Changing e.keyCode (e.
Clearing a range creat
UPDATE: My mouse over 

News Archive

onChange Help 
beforeload? vs onload.
Problem with document.
decreasing my javascri
Problem with \\ and \ 
how to stop scrolling?
Change Label Text Colo
Can I forward a page b
2 javascript functions
Validating a textbox 

Related stories:

onload for images that are dynamically generated -- a problem in IE
multiple onsubmit problem
table row display problem
stop form action from opening window
Strange Behaviour
moving the browser window
Quotes in a string
Copy link text to clipboard
Problem with htmlarea

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics