Expand my Community achievements bar.

Presence bound to multiple checkboxes

Avatar

Level 4

I have the following problem:

I have about 50 Checkboxes and 40 other fields.

Depending on which checkboxes are checked some of the 40 fields should dissappear. (Leaving behind the options the person has.)

I'd prefer some script like: "if (check1.rawValue == 1 || check2.rawValue == 1 || check5.rawValue == 1 || ......)

{this.presence = "invisible";}

else

{this.presence = "visible"}

But I don't get it to work...

Which event should I put this into? Has someone some better idea for this?

(I am not sure that really much Options in the "if sentence will" work out)

Since now I tried programming it into the checkboxes.

Problem there is: the fields don't get visible when unchecked and I don't want to put a visiblescript behind it, because it could be invisible because of other checkboxes too. If I would script it to every possible solution... OMG the leghts would be incredible... and I will have to change a lot of it.

4 Replies

Avatar

Level 4

Edit: seemed to work at first, but now doesn't anymore...

It's impossible to exchange the solved sign right?

Avatar

Level 10

Hi,

You could try this:

  • set up a function (or series of unctions) in a script object with all of the if statements.
  • call the function in the exit event of each checkbox

Good luck,

N.

PS

Another option may be to put script in the Layout:Ready event of each field/object. I think it would be easier to script which checkboxes may be ticked to make that one object visible/hidden; rather than scripting each checkbox which may affect multiple objects. Just a thought!!

N.

Avatar

Level 4

Right now it is 136 checkboxes and 12 fields.

The problem is not to make them invisible... the problem is, to get them back to visible. I can't do "else (this.presence = "visible") ... nor do I think that javascript allows a high number of && relations.

Right now I have solved it like this:

if (Kontrollkästchen4.rawValue == 1){this.presence = "invisible"; }

if (Kontrollkästchen5.rawValue == 1){this.presence = "invisible"; }

......................

(I made a script, that makes me this script)

The thing I want is simple... if specific checkboxes are checked the Field should get invisible.

If none of them is checked... or all of the checkboxes that will make it dissapear are unchecked, it should get back visible.

Like I said, making it invisible is no problem... getting it back visible is.

Avatar

Level 10

Hi,

That's a lot of variables, but I still think that you will get it to work.

In our experience Javascript can handles multiple variables OK. But here it might be useful to switch to FormCalc.

For each field, I would determine the combination of checkboxes that ALL must be ticked to make the field invisible. Then another list of single checkboxes that may be ticked to make it invisible (if that is applicable).

The following Formcalc approach should work:

if (Kontrollkästchen12 == 1 and Kontrollkästchen27 ==1 and .... Kontrollkästchen124 ==1) then //all must be ticked

     this.presence = "hidden"

elseif (Kontrollkästchen18 ==1 or Kontrollkästchen46 == 1 or ... Kontrollkästchen57 == 1) then //any one of the boxes ticked

     this.presence = "hidden"

else

     this.presence = "visible"

endif

I hope this works,

Niall