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

Determine field value based on Radio buttons - custom calculation not working

Explorer ,
Jan 31, 2025 Jan 31, 2025

Copy link to clipboard

Copied

I'm trying to do something that should be simple, but it's not working.

 

FIRST

 

I think I have the right code, but not sure:

 

var frequency = this.getField("1_Year").value;

if (frequency == "Off") {
Amount.value = "100";
}
else if (frequency == "On") {
Amount.value = "200";
}

 

Would this output "100" into field "Amount" for off and "200" for on?

 

SEDCONDLY:

 

when I type this into a custom calculation field and hit ok, acrobat closes the window as if it's accepted it, but when I look at the box, it has gone back to "value is not calculated", which is obviously not what I want.

 

Any help?

TOPICS
Edit and convert PDFs , General troubleshooting , How to , PDF , PDF forms

Views

70

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
Explorer ,
Jan 31, 2025 Jan 31, 2025

Copy link to clipboard

Copied

Well, I think I figured it out, but I can't edit or delete this post so. oh well?

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 ,
Jan 31, 2025 Jan 31, 2025

Copy link to clipboard

Copied

Here's an article that covers the basics of scripting radio buttons:

https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm

 

Basically, the default "On" value for a radio button is "Yes". But this is also the export value, which you can change to be whatever you want. 

 

 

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
Explorer ,
Jan 31, 2025 Jan 31, 2025

Copy link to clipboard

Copied

Thanks Thom, I do understand that, but my arger issue is part two. I'm writing what I think is correct code, but it's just dissappearing once I type it in. Any help there?

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 ,
Jan 31, 2025 Jan 31, 2025

Copy link to clipboard

Copied

Yeah, dissappearing calculation scripts is a big problem.  This happens when Acrobat is confused about the selected calculation type, which happens when switching between fields.  I haven't had this problem in a while because I'm very careful not to click on stuff too fast in any dialog in Acrobat. However, I understand that this issue can also happen with the built-in editor, which doesn't work that great. I would suggest setting up Acrobat with an external editor, such as Notepad++, which besides being an awesome code editor, is free. 

 

I don't know if this will fix your issue, only Adobe can know that. But it's worked for me. 

 

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
Explorer ,
Feb 01, 2025 Feb 01, 2025

Copy link to clipboard

Copied

LATEST

Thanks. So far nothing is working for me - I can't even get it to save the fields I pick for simple value calculations so... it's clearly something program based. Ugh. 

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