• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Custom calculation script not working, please help!

Engaged ,
Jul 10, 2020 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);

TOPICS
Acrobat SDK and JavaScript

Views

586

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
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 10, 2020 Jul 10, 2020

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 (" ") ?

Votes

Translate

Translate
Engaged ,
Jul 10, 2020 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 🙂 

Votes

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
community guidelines
Community Expert ,
Jul 10, 2020 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;

Votes

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
community guidelines
Engaged ,
Jul 10, 2020 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);

Votes

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
community guidelines
Engaged ,
Jul 10, 2020 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.

Votes

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
community guidelines
Community Expert ,
Jul 10, 2020 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 (" ") ?

Votes

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
community guidelines
Engaged ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Community Expert ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

The last line is probably not needed.

 

Votes

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
community guidelines
Community Expert ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

Only if you reject the value in the Validation event.

Votes

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
community guidelines
Engaged ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines