How to toggle 2 fields in Forms 2.0 | Community
Skip to main content
Grégoire_Miche2
Level 10
October 13, 2015
Solved

How to toggle 2 fields in Forms 2.0

  • October 13, 2015
  • 4 replies
  • 5468 views

Dear all,

I have 2 checkboxes in a form. I want that both cannot be checked together. So, when the 1st one is checked, I want that the second one to be unchecked immediately and vice-versa. (all this being visible to the visitor, not happening when the form is posted).

Any idea on how to do this ?

Thx in advance,

-Greg

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

Stijn_Heijthuij
Level 6
October 13, 2015

Hi Gregoire,

As far as I know there's no way to manipulate the values of fields in Forms2.0

Based on my experience, the best bet you'll have it to add some Javascript code to check/uncheck based on either of the fields.

Priyank_Joshi3
Level 5
October 13, 2015

Hi Gregoire,

Check boxes, by design, are meant to be toggled on or off. They are not dependent on other checkboxes, so you can turn as many on and off as you wish.

Radio buttons, however, are designed to only allow one element of a group to be selected at any time. I would suggest using radio buttons instead.

Thanks
Priyank

SanfordWhiteman
Level 10
October 13, 2015

I agree with Priyank that a radio button set is commonly -- though not always -- considered semantically appropriate when you want mutually exclusive selections.

Radios are meant to result in a single value stored to a single field on the back end.

Checkboxes may result in a single value on a single field, or a single value posted to one of several fields (with the other fields left at boolean false/off).

These are different use cases, and form builder limitations are another consideration. Marketo does not let you natively use radio buttons across multiple back-end fields. However, I recently posted a Forms 2.0 recipe to present independent checkboxes *as if* they were radios. Search the Community and you'll find it.

Grégoire_Miche2
Level 10
October 13, 2015

I need checkboxes, not radio buttons, since it can be a one to many relationship, such as in a subscription center.

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
October 14, 2015
Grégoire_Miche2
Level 10
October 14, 2015

Thx a lot Sanford,

Just a quick question : how do I customize the line

var mutexSelectors = '#VIP__c,  #ContactReq__c';

If I have checkbox1__c, checkbox2__c and checkbox3__c that all need to be mutually exclusive to unsubscribed field

-Greg