These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

javscript help (days between dates)

affinit
Registered: Apr 7 2009
Posts: 18
Answered

Hi everyone,

I really need help with setting up my form.

My form is a staff rental car application form.

What it does is

1) Select a Car

2) Choose the pickup & dropoff dates (if it is on the same day it's counted as 1 day)

3) Depending on the number of days there will be a different price that will show up in cost.

i have used the purchase order example that comes with Livecycle ES 8.2 to auto populate my fields(Javascript). in this case the COST field. then i can just use simple formcalc to calculate the total.

My current problem is that i can't calculate days between dates in JS. I've tried calculating in formcalc and trying to "grab" the result into a JS but still can't get it to work.

Is anyone able to help me with the date calculation so that i can pass it into my getdescription function as a variable for a IF statement.

i have attached a link to my file

http://www.bses.org.au/downloads/Steven_IT/TravelWorkout2.pdf

the extra boxes outside of the table are jsut testing cells, so i could see what was returning.

I would be greatful if anyone has any suggestions for me in how to integrate the date manipulation.

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
For calculation the amount of days, where the count is 1 if the pickoff and dropoff dates are the same, you need another calculation than your current.

$.rawValue = Date2Num(form1.Page1.Table1.Row1.dropOff.formattedValue, DateFmt(2)) - Date2Num(form1.Page1.Table1.Row1.pickUp.formattedValue, DateFmt(2)) + 1
To use this for calculating the total cost you need a script like

form1.Page1.Table1.Row1.total::calculate - (FormCalc, client)var Days = Date2Num(form1.Page1.Table1.Row1.dropOff.formattedValue, DateFmt(2)) - Date2Num(form1.Page1.Table1.Row1.pickUp.formattedValue, DateFmt(2)) + 1 $.rawValue = form1.Page1.Table1.Row1.cost.rawValue * Days

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

affinit
Registered: Apr 7 2009
Posts: 18
Hi Radzmar,

The problem i'm having is i can't get the javascript to read the days calulated from the formcalc.

i tried using java to calculate date but it's not reading in the dates fields

so i'm kinda of stuck.

i don't mind putting a hidden field with the formcalc date calculation but i need to read this number into my javascript call to populate the cost cell.

in my script it calls a function getDesciption. so i want to be able to send the number of days into this function so that when i iterate through, depending on the "days" it will select a different array.

as there will be a different cost associated with a different "days".
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi affinit,

by lookin through your form I could not find any JavaScript within.
There is always FormCalc, which is not the same.

To calculate a different cost depending on the days the car is rent I put a new script into your example form to the field "cost":

form1.Page1.Table1.Row1.cost::calculate - (FormCalc, client) var Days = Date2Num(form1.Page1.Table1.Row1.dropOff.formattedValue, DateFmt(2)) - Date2Num(form1.Page1.Table1.Row1.pickUp.formattedValue, DateFmt(2)) + 1 if (form1.Page1.Table1.Row1.car.rawValue == "Hyundai Getz") thenif (Days <= 3 ) then$.rawValue = 20.00elseif (Days <= 5 ) then$.rawValue = 18.00elseif (Days > 5) then$.rawValue = 16.00endif

elseif (form1.Page1.Table1.Row1.car.rawValue == "Toyota Yaris M Hatch") thenif (Days <= 3) then$.rawValue = 50.00elseif (Days <= 5) then$.rawValue = 45.00elseif (Days > 5) then$.rawValue = 40.00endif

elseif (form1.Page1.Table1.Row1.car.rawValue == "Toyota Yaris A Hatch") thenif (Days <= 3) then$.rawValue = 90.00elseif (Days <= 5) then$.rawValue = 80.00elseif (Days > 5) then$.rawValue = 70.00endif

endif

The field "Total" uses the script I just specified before:

 form1.Page1.Table1.Row1.total::calculate - (FormCalc, client) var Days = Date2Num(form1.Page1.Table1.Row1.dropOff.formattedValue, DateFmt(2)) - Date2Num(form1.Page1.Table1.Row1.pickUp.formattedValue, DateFmt(2)) + 1 $.rawValue = form1.Page1.Table1.Row1.cost.rawValue * Days

You can get the a working form with this script here:
https://share.acrobat.com/adc/document.do?docid=6a30c866-f32a-4121-9880-a091e952ec43

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

affinit
Registered: Apr 7 2009
Posts: 18
Hi Radzmar

I will give your code a try in the morning.

If you look in the heirachy i have a script that auto populates the car field.

its called parNoScript

its got a few arrays in there to match up cars and cost.

can formcalc do arrarys'?

but i will give your code a try first....

and see how i go
affinit
Registered: Apr 7 2009
Posts: 18
thanks Radzmar. the code is good. i was trying to work with arrays to reduce the code size. but the formcalc is working fine.

thanks for that.