Skip to main content
Inspiring
May 2, 2016
Answered

Check a specific checkbox based on a variable

  • May 2, 2016
  • 2 replies
  • 1932 views

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 ;

}

This topic has been closed for replies.
Correct answer beautiful_wisdom15A7

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.


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!

2 replies

try67
Community Expert
Community Expert
May 2, 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...

Inspiring
May 3, 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?

try67
Community Expert
Community Expert
May 3, 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 ;

}

try67
Community Expert
Community Expert
May 2, 2016

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