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

Custom calculation script not working, please help!

Engaged ,
Jul 10, 2020 Jul 10, 2020

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

Translate
Engaged ,
Jul 10, 2020 Jul 10, 2020

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 🙂 

Translate
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

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

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

To:

var b = event.value;

Translate
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

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);

Translate
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

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.

Translate
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

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

Translate
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

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

Translate
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

The last line is probably not needed.

 

Translate
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

Only if you reject the value in the Validation event.

Translate
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
LATEST

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

Translate
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