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

Check a specific checkbox based on a variable

Explorer ,
May 02, 2016 May 02, 2016

First off, I'm using checkboxes as a radiobutton in this example.

I have a series of checkboxes all named "Finish1" When I select a specific checkbox in the "Finsh1" set, I want it to look at the export values of another group of checkboxes named "Color1" and hide specific ones. What I have attempted below I'm sure is a mess and it doesn't work, but it was my best idea.

Thank you for your help!

var vc = this.getField("Color1").value;

if(vc == 3 || vc == 5 || vc == 8 || vc == 12 || vc == 13 || vc == 14  || vc == 18 || vc == 19 || vc == 20) {

       vc.display = display.hidden ;

}

else if(vc == 3 || vc == 5 || vc == 8 || vc == 12 || vc == 13 || vc == 14  || vc == 18 || vc == 19 || vc == 20) {

       vc.display = display.visible ;

}

TOPICS
Acrobat SDK and JavaScript
1.6K
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

correct answers 1 Correct answer

Explorer , May 04, 2016 May 04, 2016

What I  was thinking, was when a finish was selected, it would show all of the "Color1" checkboxes, except those that were not available in that finish. So, when a finish is selected, specific colors would not be visible.

It is not possible to hide specific checkboxes that are all named the same. The only way to get this to work is to rename them and hide or show what you want, then reset the checkbox, assuming you wanted them to react like a radiobutton.

Thanks again try67 for all of your efforts

...
Translate
Community Expert ,
May 02, 2016 May 02, 2016

Should it not take the value of Finish1 itself into consideration?

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 ,
May 02, 2016 May 02, 2016

You made a mistake because you're treating the vc variable as a field, when in fact it's the field's value.

Also, your code doesn't make sense. The conditions under the if-statement and under the else-statement that follows it are identical...

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
Explorer ,
May 03, 2016 May 03, 2016


I guess I do need the value of "Finish1" if I'm using the following method. I was just trying to see if I could get the checkboxes to hide, but I had no luck using this.

var f1 = this.getField("Finish1").value ;

var c1 = this.getField("Color1").value ;

if(f1 == 4 && c1 == 3) {

    c1.display = display.hidden ;

}

I copy and pasted the upper half of the code and I meant to change it before posting, but I got side tracked.

How would I go about pulling the value of the "Color1" checkbox set, then turning off specific ones based on their export value?

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 ,
May 03, 2016 May 03, 2016

You're  still making the same mistake as before... Your code needs to be something like this:

var f1 = this.getField("Finish1");

var c1 = this.getField("Color1");

if (Number(f1.value) == 4 && Number(c1.value) == 3) {

    c1.display = display.hidden ;

}

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
Explorer ,
May 03, 2016 May 03, 2016

I was hopeful that would work, it made a bit more sense, but unfortunately that didn't work either.

I get no response from any of the checkboxes. Is it even possible to hide and show a checkbox / radio button that has the same name? (i.e. "Color1")

Here's an image of what it looks like.

Screen Shot 2016-05-03 at 1.31.05 PM.jpg

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 ,
May 03, 2016 May 03, 2016

Are you sure you set the export values of the check-boxes (or radio-buttons) to these values?

Also, check the JS console for any error messages.

And yes, it is possible to do it.

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
Explorer ,
May 03, 2016 May 03, 2016

The error messages when entering the code into the console are:

SyntaxError: syntax error

1:Console:Exec

undefined

Edit: I still get the SytaxError, sometimes, seems to be a PDF bug. No other code changes.

I added "" to the code, and it removed the SytaxError, but the undefined remained.

The export value of "Finish1" is 4 and the export value of "Color1" is 3. They go in numerical order, so the ease of targeting specific colors would be easier.

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 ,
May 03, 2016 May 03, 2016

I don't understand. Did you change the code I provided? If so, why and how?

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
Explorer ,
May 03, 2016 May 03, 2016

When I originally added your code it gave me the SytaxError, so I added "", which then removed the SytaxError. This is what it looked like, but it still didn't fix anything and nothing reacted after changing it. So it didn't help or break anything what I did.

if (Number("f1.value") == 4 && Number("c1.value") == 3) {  

    c1.display = display.hidden ;  

Closing and re-opening the document then re-entering your code only returned "undefined". So I'm not sure what is happening.

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 ,
May 03, 2016 May 03, 2016

The original code I provided is fine, if you use it as is. Make sure you don't change the type of quotes used in it or anything else.

Your changes actually broke it. And a return value of "undefined" only means the code executed without error and without returning any values.

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
Explorer ,
May 03, 2016 May 03, 2016

I tried it as is from your original post, as I had the first time, and still no luck. Nothing has changed or indicated it was working.

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 ,
May 03, 2016 May 03, 2016

How are you running the code? Can you share the file?

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
Explorer ,
May 04, 2016 May 04, 2016

I'm running the code in the actions tab of the "Finish1" checkbox (As shown in the picture I posted. I can share it, but I can't share it in a public forum, I will send you a pm message with a link to the file.

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
Explorer ,
May 04, 2016 May 04, 2016
LATEST

What I  was thinking, was when a finish was selected, it would show all of the "Color1" checkboxes, except those that were not available in that finish. So, when a finish is selected, specific colors would not be visible.

It is not possible to hide specific checkboxes that are all named the same. The only way to get this to work is to rename them and hide or show what you want, then reset the checkbox, assuming you wanted them to react like a radiobutton.

Thanks again try67 for all of your efforts! A valuable asset to the forum!

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