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

Javascript for forms to globally change radio button from square to check button style?

Explorer ,
Mar 02, 2021 Mar 02, 2021

Copy link to clipboard

Copied

Hi, I have no idea how to write javascript but wondered if anyone has written a jave script code for the above that I could copy into my documents. There is no way in acorbat preferences to change the default from a square box to a tick box in the radio button properties when using "Prepare Form" to initate the form fields initially. Currently I have to go through the whole documents page by page to select the premade fields and change them all to a "tick" rather than a "square" as a tick box is our company style. I have got this set as a default when drawing my own radio buttons, but cant find a way to change it when the fields are automatically generated with "Prepare Form". Would be great to find some javascript code to do this globally throughout my whole document which I could add to Action Wizard.

Cheers

Gia

TOPICS
JavaScript , PDF forms

Views

1.7K

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 1 Correct answer

Community Expert , Mar 03, 2021 Mar 03, 2021

You can use this script in an Action or in the JS Console:

 

for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if (oFld.type == "checkbox" || oFld.type == "radiobutton") {oFld.style = style.ch;}
}

 

Capture_216.png

Votes

Translate

Translate
Community Expert ,
Mar 02, 2021 Mar 02, 2021

Copy link to clipboard

Copied

If I'm not incorrect, I think that there is an option when using the Prepare Form tool that allows you to set the desired default when you're working with  field objects.

 

What you need to after you create a radio  button with the desired field properties, exit the Properties dialogue window by clicking OK.

 

Then right-click on the radio button again and see at the bottom of the context menu Use Current Properties as New Defaults".

 

I am not sure if this preference is enabled globally for every document, but at least in the current document you should notice that everytime you create a new group of radio buttons they will have those defaults selected already.

 

Another way of doing this may be possible with a  JavaScript batch action script to change them all  at once.

 

Right click on the radio button object and

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 ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

You can use this script in an Action or in the JS Console:

 

for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if (oFld.type == "checkbox" || oFld.type == "radiobutton") {oFld.style = style.ch;}
}

 

Capture_216.png

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 ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Wonderful thank you so much. I could give you a big hug if such things were allowed. That will save me so much time. Works a treat.

 

Is there also away to code the radio button appearance so there is always no line, no fill, indent etc and the box surrounding the "check" is therefore always invisible?

 

Cheers Gia

 

 

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 ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

We just need to add two lines of Javascript

 

for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if (oFld.type == "checkbox" || oFld.type == "radiobutton") {
oFld.style = style.ch;
oFld.strokeColor = color.transparent;
oFld.fillColor = color.transparent;
}
}

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 ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Thank you once again. Could I also ask, what the code would be if I wanted to change all of the "checkboxes" that come in as style.sq to style.ch? I tried to juggle the code myself, but as I have absolutely no idea what Im doing couldn't get it to work.

Thank you for your wonderful help.

Cheers

Gia

 

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 ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

"what the code would be if I wanted to change all of the "checkboxes" that come in as style.sq to style.ch?"

for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if (oFld.type == "checkbox" && oFld.style == style.sq) {oFld.style = style.ch}

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 ,
Mar 10, 2021 Mar 10, 2021

Copy link to clipboard

Copied

Thank you so much for all your help.

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

LATEST

Hi, sorry one more question regarding these javascript codes. I have found that sometimes they work and sometimes they don't work on the pdfs. The original artwork is always made in InDesign, and then exported to pdf, and then the pdf opened in Acrobat Pro DC (latest version) and then "Prepare Form" to make the editable fields. The "checkbox" fields for example, that this produces when they are detected (not always sadly) are always style.sq, but on some documents your code works to change them to style.ch and on some documents it just doesnt work. These documents have been made with exactly the same process. I was wondering if you had any idea on why the javascript works sometimes and sometimes not? It is not just this code that doesnt work, but other javascript I have been using too. Thank you once again for all your help. I would love to understand all this. Cheers Gia

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