Clear script generated data in a form field

Feb 05, 2019

Copy link to clipboard

Copied

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

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

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

141

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Clear script generated data in a form field

Feb 05, 2019

Copy link to clipboard

Copied

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

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

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

142

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 05, 2019 0
Feb 06, 2019

Copy link to clipboard

Copied

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

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2019 1
Feb 06, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2019 0