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

How do I Make Multiple Copies of a Radio Button AND keep the Java Script

New Here ,
Feb 15, 2018 Feb 15, 2018

I am trying to make multiple copies of a radio button group AND keep the Java Script that I have input. I have 1 group of 3 radio buttons that has a script, I seem to be unable to copy the radio button while still retaining the java script. It doesn't copy with the new buttons!

TOPICS
PDF forms
4.1K
Translate
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 ,
Feb 15, 2018 Feb 15, 2018

What mechanism are you using to copy the buttons?

When I copy a radio button using ctrl-C/ctrl-v, all properties are copied.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Feb 15, 2018 Feb 15, 2018

If I use ctrl-C/ctrl-V-yes the properties are all copied but then when you select one of the buttons the other is selected as well. I would have to go back and rename them all.

Translate
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 ,
Feb 15, 2018 Feb 15, 2018

Yes, when you copy fields you have to rename them. That's how it works. That's got nothing to do with the JavaScript.

An alternative to the copy/paste is to use the "Create Mulitple Copies" option on the Right Click pop up menu that appears when you have fields selected. I believe this option renames the fields.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Feb 15, 2018 Feb 15, 2018

But as I said if I use the 'Create Multiple Copies' option, the java script does not copy. I am wondering how, or, if there is a way to create multiple copies of the radio button group and have the java script copy with it, without my having to go back and either rename every field (like with the ctrl-C/ctrl-V) or add the script (as with 'Create Multiple Copies') to every field separately. Maybe it cannot be done?

Translate
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 ,
Feb 15, 2018 Feb 15, 2018

You need to be clear about what it is you want to do. The "Create Multiple Copies" feature gives each field a new name and copies the JavaScript. So you shouldn't be having a problem.

However, if it isn't working for you, there is a way through scripting to add scripts to a field. This would be relatively easy way to add scripts to the copied buttons.

What kind of script are you using? What does the script do?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Feb 16, 2018 Feb 16, 2018

Maybe I am going about this wrong, here's my situation:  When I select a group of 3 radio buttons and try to 'Create Multiple Copies' I get this message "Cannot create multiple copies of this selection. One or more fields in the selection have duplicates in this form."

I am unable to make multiple copies of the group of radio buttons. I can use 'Create Multiple Copies' and copy one button. What I would like to do is to copy the group of 3, 22 times (and keep the script). Here is the script I am using:

if(event.target.oldVal == event.target.value)event.target.value = "Off";

it allows the user to uncheck the radio button, otherwise I found that one button out of the group would always have to be selected once the user selects one in the group (ie: they can't uncheck a button and leave the group blank) and I don't want that.

Translate
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 ,
Feb 16, 2018 Feb 16, 2018

So you have a couple of issues.

First, as the message states, there is a duplicate of the fields you are trying to copy. Get rid of it and "Create Multiple Copies" will work. You can just rename the duplicate to something else.

Next, you don't need the script for turning the radiobutton off. Just use CheckBoxes instead of radio buttons.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Feb 16, 2018 Feb 16, 2018

Check boxes are not an option for this project, it has to be radio buttons. And I don't want the user to be able to select more than 1 in every group of 3.

Translate
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 ,
Feb 16, 2018 Feb 16, 2018
LATEST

In a PDF, Checkboxes and Radio buttons are almost the same thing. Give two check boxes the same name and different export values and they act just like two radio buttons, except you can click them off.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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