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.
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.
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("%", "");
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;
Copy link to clipboard
Copied
Make sure field name is Deposit.
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.
Copy link to clipboard
Copied
Thank you Nesa for your line of code also worked great. Thank you very much for your quick response.
Copy link to clipboard
Copied
Hi there,
How can i change a dropdown list item with a click of a button. Your method works for a text box. But not working for a dropdown list.
Pls help
Thanks
Copy link to clipboard
Copied
It should work just the same. Of course, the value you select must be one of the options in the field's list.
Copy link to clipboard
Copied
I have tried it. Somehow it dont works
Copy link to clipboard
Copied
You need to be more specific if you want help with this issue. Are there any error messages in the Console? What exactly happens when you use it? Can you share the code, or the actual file with us?
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("%", "");
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.
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.
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?
Copy link to clipboard
Copied
yes by default it should show zero.
Copy link to clipboard
Copied
I mean before any buttons are clicked it should display "0" by default, thanks
Copy link to clipboard
Copied
That would mean that the value you selected will not be saved when you close the file, though...
Copy link to clipboard
Copied
Yes exactly, when I close the document the value should not be saved.
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;
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,
Copy link to clipboard
Copied
Can you post a screenshot of where you placed the code, or share the file with us?
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
Copy link to clipboard
Copied
Seems fine. Can you share the actual file?
Copy link to clipboard
Copied
Make sure field name is Deposit.
Copy link to clipboard
Copied
Thank you for asking me to check field name,
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,

