Skip to main content
Mohammed Mahmood
Participating Frequently
June 19, 2021
Answered

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

  • June 19, 2021
  • 2 replies
  • 9249 views

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.

This topic has been closed for replies.
Correct answer Nesa Nurani

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


Make sure field name is Deposit.

2 replies

try67
Community Expert
June 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("%", "");

Mohammed Mahmood
Participating Frequently
June 19, 2021

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.

try67
Community Expert
June 19, 2021

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

Nesa Nurani
Community Expert
June 19, 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.

Mohammed Mahmood
Participating Frequently
June 19, 2021

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