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

custom javascript if checkbox checked

Community Beginner ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

My knowledge of Javascript is very basic and I have a pdf form I cannot figure out the javascript.

I need to calculate taxes based on which checkbox is checked.

 

If checkbox 1 is checked, then need to calculate Federal tax (5%) on the "total", if checkbox 2 is checked then the value is 0, if checkbox3 is checked then a manual entry is to be made

 

 

TOPICS
PDF forms

Views

2.8K

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

For this you definately need a script.

Are these "checkboxes" mutually exclusive? i.e radio buttons.  Or are they completely different checkboxes?

 

So here's a script that assumes the "checkboxes" are really radio buttons named "TaxType", with export values of  "Choice1", "Choice2","Choice3". 

This script goes into the custom calculation on Tax field.

 

 

var nTotal = Number(this.getField("Total").value);
var nChoice = this.getField("TaxType").value;
// block manual entry
event.target.readonly 
...

Votes

Translate

Translate
Community Expert ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

For this you definately need a script.

Are these "checkboxes" mutually exclusive? i.e radio buttons.  Or are they completely different checkboxes?

 

So here's a script that assumes the "checkboxes" are really radio buttons named "TaxType", with export values of  "Choice1", "Choice2","Choice3". 

This script goes into the custom calculation on Tax field.

 

 

var nTotal = Number(this.getField("Total").value);
var nChoice = this.getField("TaxType").value;
// block manual entry
event.target.readonly = true;

switch(nChoice)
{
    case "Choice1":
      event.value = .05 * nTotal;
      break;
    case "Choice2":
      event.value = 0;
      break;
    case "Choice3":
      event.rc = false; // This allows for manual entry
      event.target.readonly = false;
      break;
    default:
      event.value = "";
      break;
}

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

it works perfectly.  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 Beginner ,
Oct 20, 2020 Oct 20, 2020

Copy link to clipboard

Copied

On the same document, I am trying to calculate a percentage (GP%).  My script is very simple:  Margin/Total. However, the form user will get an error message "The value entered does not match the format of the field (GP).  The user can bypass by clicking OK but this is not ideal.  I understand that the error message happens when the value is 0 but I do not know how to fix that 

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

Copy link to clipboard

Copied

LATEST

A common issue. Here's an article on the topic:

https://www.pdfscripting.com/public/Value-Entered-Does-Not-Match-Format.cfm?sd=40

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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