Copy link to clipboard
Copied
I am making a time card, and I have 4 times per daily total. The first 2 are for before lunch, and the second 2 are for after lunch. If any of the fields are blank, the total returns as NaN. I would like for them to calculate as zero if their text box is blank, and I don't know how to go about doing this.
// Get first field value
var v1 = getField("End1").value;
//Split field value
var time1 = v1.split(":");
// Get second field value
var v2 = getField("Start1").value;
//Split field value
var time2 = v2.split(":");
// Get third field value
var v3 = getField("End2").value;
//Split field value
var time3 = v3.split(":");
// Get fourth field value
var v4 = getField("Start2").value;
//Split field value
var time4 = v4.split(":");
var min1 = time1[0]*60 + time1[1]*1 //
var min2 = time2[0]*60 + time2[1]*1 //
var min3 = time3[0]*60 + time3[1]*1 //
var min4 = time4[0]*60 + time4[1]*1 ;
if( Start1 = "" ) event.value = 0;
else event.value = ((min1 - min2) / 60)+((min3 - min4) / 60);
I tried changing ( Start1 = "" ) to ( Start1 == "" ), but that didn't change anything. I don't know much about Java, just what I have been able to google. As I said, each daily total has 4 times with textboxes. If any one of them is blank, NaN is returned. I would like it if either Start1 or Start2 are blank, their part of the calculation would return zero. So if Start1 and Start2 are blank, return zero. If Start2 is blank, do End1 - Start1. If Start1 is blank and Start2 isn't, End2 - Start2. And finally if neither Start1 or Start2 are blank, (End1 - Start1) + (End2 - Start2).
Copy link to clipboard
Copied
You haven't defined or set a variable named "Start1" anywhere. The variable v2 seems to be the closest. You should get the field values using the valueAsString property instead of the value property, and use the comparison operator == instead of the assignment operator = when comparing the value to an empty string ("").
Find more inspiration, events, and resources on the new Adobe Community
Explore Now