Highlighted

custom javascript if checkbox checked

Community Beginner ,
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

 

 

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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

 

 

TOPICS
PDF forms

Views

41

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 javascript if checkbox checked

Community Beginner ,
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

 

 

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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

 

 

TOPICS
PDF forms

Views

42

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
Oct 15, 2020 0
Adobe Community Professional ,
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;
}

 

 

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

Copy link to clipboard

Copied

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

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...
Oct 20, 2020 0
Adobe Community Professional ,
Oct 20, 2020

Copy link to clipboard

Copied

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