Skip to main content
Participant
February 6, 2019
Answered

Clear script generated data in a form field

  • February 6, 2019
  • 1 reply
  • 850 views

I have a form that I am creating that has a "Clear Form" button on it that clears all of the form fields.  For the most part, this works except for three fields that calculate a date based on a script.  The three fields I am having problems are selected to be part of the "clear form" action.

What I would like help with is with is to either to modify the script to return a blank output if there is nothing in the input field or for the "clear form" button too clear everything.

The script I am using is as follows

var sDate = this.getField("InterviewComplete_af_date").value; // get date string

var oDate = util.scand("yyyy/mm/dd", sDate); // convert to object

var nDay = 1000 * 60 * 60 * 24; // define 1 day in milliseconds

var nDate = oDate.getTime() + (5 * nDay); // add 5 days as milliseconds

oDate = new Date(nDate); // convert milliseconds to date object

event.value = util.printd("yyyy/mm/dd", oDate); // format result

This topic has been closed for replies.
Correct answer try67

Change it to:

var sDate = this.getField("InterviewComplete_af_date").valueAsString; // get date string

if (sDate=="") event.value = "";

else {

    var oDate = util.scand("yyyy/mm/dd", sDate); // convert to object

    var nDay = 1000 * 60 * 60 * 24; // define 1 day in milliseconds

    var nDate = oDate.getTime() + (5 * nDay); // add 5 days as milliseconds

    oDate = new Date(nDate); // convert milliseconds to date object

    event.value = util.printd("yyyy/mm/dd", oDate); // format result

}

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 6, 2019

Change it to:

var sDate = this.getField("InterviewComplete_af_date").valueAsString; // get date string

if (sDate=="") event.value = "";

else {

    var oDate = util.scand("yyyy/mm/dd", sDate); // convert to object

    var nDay = 1000 * 60 * 60 * 24; // define 1 day in milliseconds

    var nDate = oDate.getTime() + (5 * nDay); // add 5 days as milliseconds

    oDate = new Date(nDate); // convert milliseconds to date object

    event.value = util.printd("yyyy/mm/dd", oDate); // format result

}

Participant
February 6, 2019

That worked perfectly for my needs, Thank you for the help !!