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

Calculation validation script based on radio button and checkbox

New Here ,
Oct 26, 2020 Oct 26, 2020

Copy link to clipboard

Copied

I would like help with the following please:

 

  1.  Radio button group 'Soort' existing of options 'New' and 'Damaged'.
  2. When 'Damaged' is selected, 4 checkboxes appear: 'VZ', 'AZ', 'BZ', 'PZ'.
  3. When for instance 'VZ' is selected, checkboxes 'V1', 'V2', and 'V3' appear, each containing a different value. Same for 'AZ' ('A1', 'A2', ...) and the other ones.
  4. 'Total' is the field for the result of the calculation, based on the input.

 

When 'New' is selected the calculated value of 'Total' must be overwritten with value '795', otherwise the values of 'V1', 'V2', 'V3', 'A1', 'A2', and so on must be added up to 'Total'.

 

I currently have place this script to the 'Total' field (tab Calculate, alternate calulated script), but keep getting errors when 'Damaged' is selected (possibly because the underlying options are not selected yet?):

 

var soort = this.getField("Soort").valueAsString;

if (soort=="New") { event.value = "795"; }

else if (soort=="Damaged")

{ var v1=this.getField("V1").value;

var v2=this.getField("V2").value;

var v3=this.getField("V3").value;

var v4=this.getField("V4").value;            //and so on...

event.value = 0+v1+v2+v3+v4; }

TOPICS
Acrobat SDK and JavaScript

Views

961

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 ,
Oct 26, 2020 Oct 26, 2020

Copy link to clipboard

Copied

Create hidden text field, in that field go to calculate tab and use "value is the" and pick all of your checkboxes that you want to calculate( v1-v4, a1-a4...etc)
then in total field use this code:
var sort = this.getField("Soort").valueAsString;
var hid = Number(this.getField("Hiddenfield").valueAsString);

if(sort == "New"){
event.value = "795";}
else if(sort == "Damaged"){
event.value = hid;}

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
New Here ,
Oct 27, 2020 Oct 27, 2020

Copy link to clipboard

Copied

Almost... The error message have dissappeared 🙂

 

Unfortunately at selecting the checkboxes, the values aren't calculated at once. So I get 'delayed' feedback, and therefore incorrect values within the field 'Total'.

 

For instance: Value of checkbox 'V1' = 17,40. On selection the value of 'Total' doesn't change. On de-selection thereafter the value of 'Total' changes to 17,40 ...

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 ,
Oct 27, 2020 Oct 27, 2020

Copy link to clipboard

Copied

Go to field calculation order and make sure hidden field is above total field, that should fix delay. 

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 ,
Oct 26, 2020 Oct 26, 2020

Copy link to clipboard

Copied

What error messages does you get?

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
New Here ,
Oct 27, 2020 Oct 27, 2020

Copy link to clipboard

Copied

The entered value does not match the format of the field

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 ,
Oct 27, 2020 Oct 27, 2020

Copy link to clipboard

Copied

This is most likely because you're using a number format that isn't acceptable for a script. You mentioned "17,40". If you want to enter it like that then you have to use the "1.234,56" option under Number in the field's Format tab, so that it would know you're using the comma as the decimal separator. If you don't do that it won't be able to convert this value to a number.

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
New Here ,
Oct 27, 2020 Oct 27, 2020

Copy link to clipboard

Copied

Thank you Bernd. Just checked, but this is already the case. Maybe it's because the value comes from a 'checkbox', in which I can't define the format of the exported 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
Community Expert ,
Oct 27, 2020 Oct 27, 2020

Copy link to clipboard

Copied

Set the format of the total field to "None". What can you see as result?

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
New Here ,
Oct 27, 2020 Oct 27, 2020

Copy link to clipboard

Copied

Good thinking. Something strange is happening now:

The value of 'Total' is now e.g. 017,40OffOff17,40

Off appears for the checkboxes which are not selected, 17,40 for the checked ones.

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 ,
Oct 27, 2020 Oct 27, 2020

Copy link to clipboard

Copied

LATEST

Change the export values to "17.4", instead of "17,4", and change the last line of code to:

 

event.value = 0;
if (v1!="Off") event.value+=Number(v1);
if (v2!="Off") event.value+=Number(v2);

 

etc.

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