Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Rules are probably best described by using examples. This chapter contains numerous real world samples.

...

Code Block
/*member description productId resultSet */
var x;
 
if (form.load) { 
eval('x=' + http.get('http://localhost:8082/database/products'));   
 
    var opts1 = []; 
    var opts2 = []; 
 
    for (var i=0; i < x.resultSet.length; i++) { 
        if (x.resultSet[i]) { 
            opts1[i] = x.resultSet[i].description; 
            opts2[i] = x.resultSet[i].productId; 
    } 
} 
 
 
Products.options = opts1; 
PID.options = opts2; 
Products.value = opts1[0]; // default to 1st product option 
PID.value = opts2[0]; 
}

Finding a Selected Options Index

The 2nd rule Select Product ID keeps the hidden PID dropdown syncronized with the visible Products dropdown.

...

Code Block
/ Calculate Hospital Stay Duration 
if (A.value !== '' && D.value !== '') { 
    var da = A.value.split('-'); 
    var Ams = new Date(da[0],da[1],da[2]); 
    da = D.value.split('-'); 
    var Dms = new Date(da[0],da[1],da[2]);
 
    if (Ams > Dms) { 
        Days.value = 'Discharge date must be after Admission Date'; 
    } else { 
        Days.value = (Dms - Ams) / (1000*60*60*24) + ' days'; 
    } 
}
 

Duration (between Date/Time)

Here is a rule example to calculate the time difference between two Date/Time values in hours:minutes format :

Code Block
 if (StartDateTime.value !== '' && EndDateTime.value !== '') {
 
    var d = StartDateTime.value.split('-');
    var d1 = d[2].split('T');
    var t = d1[1].split('Z')[0];
    var t1 = t.split(':');
    var startDate = new Date(d[0],d[1],d1[0], t1[0], t1[1], t1[2]);
 
    d = EndDateTime.value.split('-');
    d1 = d[2].split('T');
    t = d1[1].split('Z')[0];
    var t1 = t.split(':');
    var endDate = new Date(d[0],d[1],d1[0], t1[0], t1[1], t1[2]);
 
    var diff = endDate.getTime() - startDate.getTime();
    var hours = Math.floor(diff / 1000 / 60 / 60);
    diff -= hours * 1000 * 60 * 60;
    var minutes = Math.floor(diff / 1000 / 60);
 
    TimeToComplete.value = (hours < 9 ? "0" : "") + hours + ":" + (minutes < 9 ? "0" : "") + minutes;
 
}

 

Today's Date and Time

Use 's built-in date and time methods to set your date, time, and date/time controls to the current date and time in the user's local timezone.

...