Expand my Community achievements bar.

javascript with checkboxes

Avatar

Former Community Member
Hi,



I am trying to use to javascript to control checkboxes so that when checkbox1 is selected, checkbox2 is deselected and vice versa. Only one checkbox can be selected at a time.



I know this is fairly simple but I am a novice so I would appreciate some guidance if possible.



Thanks a lot :)
7 Replies

Avatar

Former Community Member
Hello Joseph,



it would be easier to use radio buttons to do that as they are mutually exclusive. see Designer help. also there are other posts in this forum on that subject.



Regards



Benoit

Avatar

Former Community Member
Thank you Benoit.



I have found a solution using radio buttons with:



if(this.butSet)

this.rawValue = 0;



on mouse up and



this.butSet = this.rawValue && (this.rawValue > 0);



on mouse down.



I have 3 radios but now I need to add a behaviour to make 2 of them not mutually exclusive so they can be selected together, or alone.



I did check the forums but couldn't find a solution to this.



Hope you can help.



Thanks!

Avatar

Former Community Member
Hello Joseph,



Thanks for sharing your solution. I'm afraid I cannot be of further help. Let's hope someone knows a way.



Regards



Benoit

Avatar

Former Community Member
How do you apply this code to the hidden field?

Avatar

Former Community Member
Hi Joseph,



If you still want to use check boxes take a look at this form:



https://mcanet.mcga.gov.uk/adobe/formspublic/CG/MSF6037.pdf



The check boxes in the 'TYPE OF CRAFT & CAPACITY' section are mutually exclusive.



The other check boxes are not mutually exclusive.



Hope this helps.



John

Avatar

Former Community Member
Hi John,



I saw the form you mentioned in your post, and the mutually exclusive check boxes are what I wanted.



But how do you do it? Could you explain it please? I am using Adobe Designer 7.0.



Thank you!



Baoqing

Avatar

Former Community Member
you can save the form, open it in designer & check the javascript -



Edit: just checked myself.. on click of each checkbox, they are setting each of the other checkboxes to their Off value (0 in this case which is also the default I think)



This is the script on Checkbox of name Type_Box_1 - As you can see, they are setting all checkboxes to zero apart from the one the user will click: (Type_Box_01 is missing from the following)



Type.Type_Box_02.rawValue =

Type.Type_Box_03.rawValue =

Type.Type_Box_04.rawValue =

Type.Type_Box_05.rawValue =

Type.Type_Box_06.rawValue =

Type.Type_Box_07.rawValue =

Type.Type_Box_08.rawValue =

Type.Type_Box_09.rawValue = 0;