Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


How to get a button value in another text filed if specific button is clicked

Community Beginner ,
Jun 18, 2021 Jun 18, 2021

Copy link to clipboard

Copied

Hi, Could someone help me in adding a script to my PDF form,  I have 8 buttons namely (5%, 10%, 15%, 20%, 25%, 30%, 35%, 40%), if one click on one of the buttons the value of that button should be displayed in another field called "Deposit" dynamically.  For example if I click on 10% button, the "Deposit" field should display 10 and if I click on 30%button it should display 30 in "Deposit" field.  And I would like to use the said value for calculating the percent and add it to the sub-total and display in the "Total" field.

Thanks in advance.

TOPICS
PDF forms

Views

1.5K

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

correct answers 4 Correct answers

Adobe Community Professional , Jun 18, 2021 Jun 18, 2021
In each  Button actions tab as 'Mouse UP' event,select 'Run javascript' and add this code: this.getField("Deposit").value = 5; Of course change 5 to each button value.

Likes

Translate

Translate
Adobe Community Professional , Jun 19, 2021 Jun 19, 2021
Buttons don't have a value. I assume you mean the label. In that case you can use something like this as the MouseUp event of all the buttons: this.getField("Deposit").value = event.target.buttonGetCaption().replace("%", "");

Likes

Translate

Translate
Adobe Community Professional , Jun 19, 2021 Jun 19, 2021
Go to Tools - JavaScript - Document Javascripts and create a new item. Call it "load", for example. Delete all the default code that's generated and replace it with the following: this.getField("Deposit").value = 0;

Likes

Translate

Translate
Adobe Community Professional , Jun 21, 2021 Jun 21, 2021
Make sure field name is Deposit.

Likes

Translate

Translate
Adobe Community Professional ,
Jun 18, 2021 Jun 18, 2021

Copy link to clipboard

Copied

In each  Button actions tab as 'Mouse UP' event,select 'Run javascript' and add this code:

this.getField("Deposit").value = 5;

Of course change 5 to each button value.

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
community guidelines
Community Beginner ,
Jun 19, 2021 Jun 19, 2021

Copy link to clipboard

Copied

Thank you Nesa for your line of code also worked great. Thank you very much for your quick response.

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
community guidelines
Adobe Community Professional ,
Jun 19, 2021 Jun 19, 2021

Copy link to clipboard

Copied

Buttons don't have a value. I assume you mean the label.

In that case you can use something like this as the MouseUp event of all the buttons:

 

this.getField("Deposit").value = event.target.buttonGetCaption().replace("%", "");

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
community guidelines
Community Beginner ,
Jun 19, 2021 Jun 19, 2021

Copy link to clipboard

Copied

Thank you very much, I can't thank you enough. I have spent hours figuring it out .  Thanks to Adobe's community here I got the solution.  Thank you once again.

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
community guidelines
Community Beginner ,
Jun 19, 2021 Jun 19, 2021

Copy link to clipboard

Copied

Hi there, can I keep the Deposit field "0" zero by default?  Since it is showing the last value I have entered, I am sorry if I am bothering you again, thanks in advance.

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
community guidelines
Adobe Community Professional ,
Jun 19, 2021 Jun 19, 2021

Copy link to clipboard

Copied

What do you mean by "by default", exactly? When should it show zero? When the file is opened, and before any buttons are clicked?

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
community guidelines
Community Beginner ,
Jun 19, 2021 Jun 19, 2021

Copy link to clipboard

Copied

yes by default it should show zero.

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
community guidelines
Community Beginner ,
Jun 19, 2021 Jun 19, 2021

Copy link to clipboard

Copied

I mean before any buttons are clicked it should display "0" by default, thanks

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
community guidelines
Adobe Community Professional ,
Jun 19, 2021 Jun 19, 2021

Copy link to clipboard

Copied

That would mean that the value you selected will not be saved when you close the file, though...

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
community guidelines
Community Beginner ,
Jun 19, 2021 Jun 19, 2021

Copy link to clipboard

Copied

Yes exactly, when I close the document the value should not be saved.

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
community guidelines
Adobe Community Professional ,
Jun 19, 2021 Jun 19, 2021

Copy link to clipboard

Copied

Go to Tools - JavaScript - Document Javascripts and create a new item. Call it "load", for example.

Delete all the default code that's generated and replace it with the following:

this.getField("Deposit").value = 0;

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
community guidelines
Community Beginner ,
Jun 19, 2021 Jun 19, 2021

Copy link to clipboard

Copied

HI, thanks for the piece of code, I have added the code as you instructed but the deposit value still remains and not going zero, 

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
community guidelines
Adobe Community Professional ,
Jun 20, 2021 Jun 20, 2021

Copy link to clipboard

Copied

Can you post a screenshot of where you placed the code, or share the file with us?

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
community guidelines
Community Beginner ,
Jun 20, 2021 Jun 20, 2021

Copy link to clipboard

Copied

Sure, I am attaching the screenshot where I put the code and you can see by default 5 is displayed by default. thanks

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
community guidelines
Adobe Community Professional ,
Jun 20, 2021 Jun 20, 2021

Copy link to clipboard

Copied

Seems fine. Can you share the actual file?

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
community guidelines
Adobe Community Professional ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

Make sure field name is Deposit.

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
community guidelines
Community Beginner ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

LATEST


Thank you for asking me to check field name,

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
community guidelines
Community Beginner ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

Hi, it worked, actually the field id i was entering incorrect.  After adding correct field ID it worked.  Thanks once again you saved my day, 

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