Custom calculation script not working, please help!

Contributor ,
Jul 10, 2020

Copy link to clipboard

Copied

I don't know why this isn't working. 

I entered the following in custom calculation script in the RegHrs1 text field, but I'm not getting the alert when the Shift Premium checkbox is ticked.  What am I doing wrong??

 

var a = this.getField("ShiftPrem1").value;
var b = this.getField("RegHrs1").valueAsString;


if(a=="Off") event.value=b;
else if (a=="Yes") event.value="";
if ( (b!=="") && (a=="Yes") ) app.alert("Please enter hours first",0);

This should be enough...

 

var a = this.getField("ShiftPrem1").value;
var b = event.value;
if ( (b=="") && (a=="Yes") ) app.alert("Please enter hours first",0);
this.getField("RegHrs1").setFocus(); 

 


I have added the focus back to the field.

@try67 is there a way to set back focus to self without having to use this.getField (" ") ?

TOPICS
Acrobat SDK and JavaScript

Views

98

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

Custom calculation script not working, please help!

Contributor ,
Jul 10, 2020

Copy link to clipboard

Copied

I don't know why this isn't working. 

I entered the following in custom calculation script in the RegHrs1 text field, but I'm not getting the alert when the Shift Premium checkbox is ticked.  What am I doing wrong??

 

var a = this.getField("ShiftPrem1").value;
var b = this.getField("RegHrs1").valueAsString;


if(a=="Off") event.value=b;
else if (a=="Yes") event.value="";
if ( (b!=="") && (a=="Yes") ) app.alert("Please enter hours first",0);

This should be enough...

 

var a = this.getField("ShiftPrem1").value;
var b = event.value;
if ( (b=="") && (a=="Yes") ) app.alert("Please enter hours first",0);
this.getField("RegHrs1").setFocus(); 

 


I have added the focus back to the field.

@try67 is there a way to set back focus to self without having to use this.getField (" ") ?

TOPICS
Acrobat SDK and JavaScript

Views

99

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
Jul 10, 2020 0
Contributor ,
Jul 10, 2020

Copy link to clipboard

Copied

Okay, it works when I enter hours in the text field and then click on the checkbox, but that's the opposite of what I need.  I need the alert if there are no hours entered in RegHrs1 text field when the user checks the Shift Premium box.  Please help me, I don't know what to do 🙂 

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...
Jul 10, 2020 0
Most Valuable Participant ,
Jul 10, 2020

Copy link to clipboard

Copied

You're accessing the field's previous value. Change this line:

var b = this.getField("RegHrs1").valueAsString;

To:

var b = event.value;

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...
Jul 10, 2020 0
Contributor ,
Jul 10, 2020

Copy link to clipboard

Copied

I entered the following Custom Calculation script in the RegHrs1 text field, but it still only shows the alert when text is filled in RegHrs, not if the user checks the box if the text field is blank.  What am I missing?

var a = this.getField("ShiftPrem1").value;
var b = event.value;


if(a=="Off") event.value=b;
else if (a=="Yes") event.value="";
if ( (b!=="") && (a=="Yes") ) app.alert("Please enter hours first",0);

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...
Jul 10, 2020 0
Contributor ,
Jul 10, 2020

Copy link to clipboard

Copied

I hope that makes sense, I only want the alert to show if the user checks the Shift Prem checkbox without entering hours in the RegHrs text field, but it only pops up when hours have been entered.

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...
Jul 10, 2020 0
Advocate ,
Jul 10, 2020

Copy link to clipboard

Copied

This should be enough...

 

var a = this.getField("ShiftPrem1").value;
var b = event.value;
if ( (b=="") && (a=="Yes") ) app.alert("Please enter hours first",0);
this.getField("RegHrs1").setFocus(); 

 


I have added the focus back to the field.

@try67 is there a way to set back focus to self without having to use this.getField (" ") ?

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...
Jul 10, 2020 0
Contributor ,
Jul 10, 2020

Copy link to clipboard

Copied

Fantastic!!  That's works!!  Thank you so much!!  

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...
Jul 10, 2020 0
Advocate ,
Jul 10, 2020

Copy link to clipboard

Copied

The last line is probably not needed.

 

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...
Jul 10, 2020 0
Most Valuable Participant ,
Jul 10, 2020

Copy link to clipboard

Copied

Only if you reject the value in the Validation event.

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...
Jul 10, 2020 0
Contributor ,
Jul 10, 2020

Copy link to clipboard

Copied

Thank you both so much!!  I really appreciate it!!!

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...
Jul 10, 2020 0