Quantcast
Channel: Adobe Community : Popular Discussions - JavaScript
Viewing all articles
Browse latest Browse all 12130

If/Else Javascript Request - Date Calculations

$
0
0

Hi Everyone,

 

I am working on a Travel Authorization Request form. There is a section that asks for a departure date, return date, and total days.

 

In the total days field, I have placed a script that calculates the number of days based on the departure and return date, plus 1 day. This is so that if the dates are 06/01/13 - 06/03/13, the total days is 3, not 2.

 

The script is below:

 

var sDate1=this.getField("Return Date").value;
var sDate2=this.getField("Departure Date").value;
var oDate1 = util.scand("mm/dd/yyyy", sDate1);
var oDate2 = util.scand("mm/dd/yyyy", sDate2);

var nDay = 1000 * 60 * 60 * 24;

var eDays=Math.abs(oDate1-oDate2)/nDay + 1;

event.value=Math.round(eDays);

 

The problem is, when the departure and return date fields are blank, there is still a 1 in the total days field.

Picture1.png

I need to add to this script, so that when the departure and return date fields are blank, nothing, or atleast a zero, appears in the total days field.

 

Please note, I am completely new to javascript and the one I used above, I found through internet searches.

 

Thanks :-)


Viewing all articles
Browse latest Browse all 12130

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>