Mylene 0 Posted February 20, 2017 Report Share Posted February 20, 2017 Hey, everyone! I need help again I'd like to check a checkbox when another checkbox is checked and vice versa. I have a submission form with virtual field. And if that field is checked I need to check the "Subscribed" checkbox field on the same datapage. Thanks! Quote Link to post Share on other sites
Mathilda 66 Posted February 20, 2017 Report Share Posted February 20, 2017 Just now, Mylene said: Hey, everyone! I need help again I'd like to check a checkbox when another checkbox is checked and vice versa. I have a submission form with virtual field. And if that field is checked I need to check the "Subscribed" checkbox field on the same datapage. Thanks! Hi Mylene, I have a solution for you. Use the following script in the footer of the form: <script> document.getElementById("cbParamVirtual1").onchange= function() { if (document.getElementById("cbParamVirtual1").checked==true) { document.getElementById("InsertRecordPublished").checked=true; } else if (document.getElementById("cbParamVirtual1").checked==false) { document.getElementById("InsertRecordSubscribed").checked=false; } } </script> In my script the virtual field has index "1", because my virtual field id the first one on the datapage. You may find more info about referencing virtual fields here Also replace "Subscribed" with your fieldname. Quote Link to post Share on other sites
nightowl 5 Posted September 26, 2017 Report Share Posted September 26, 2017 Hi Mylene, You can also try this script: <script> var checkboxesToCheck = [ // TODO: Add here the HTML IDs of checkboxes to check --> 'InsertRecordPublished', 'InsertRecordSubscribed', 'cbParamVirtual2', 'cbParamVirtual3', ]; var vfield = document.getElementById('cbParamVirtual1'); vfield.onchange = function () { checkboxesToCheck.forEach( function (id, index) { document.getElementById(id).checked = vfield.checked; } ); } </script> Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.