SDDENR Posted November 6, 2014 Report Share Posted November 6, 2014 I have a submission form with a couple of checkboxes. Ideally, it would be mandatory for one of the two checkboxes to be selected. However, my primary concern is that both checkboxes cannot be selected so I want to toggle off one when the other is checked. I have been playing around with other javascript code I have found on the Caspio forum but have not had any success getting it modified and working. Following is my attempted code on two checkboxes, one named "pure" and the other "mix". Any help for a javascript newcomer would be appreciated... <script type="text/javascript">/* Get value of the Yes/No fields */var cb_pure = '[@field:pure]'; var cb_mix = '[@field:mix]';if (cb_pure == 'Yes'){/* make sure cb_mix is deselected */ document.getElementById("InsertRecordmix").checked=false;}if (cb_mix == 'Yes'){/* make sure cb_pure is deselected */ document.getElementById("InsertRecordpure").checked=false;}</script> Quote Link to comment Share on other sites More sharing options...
Jan Posted November 7, 2014 Report Share Posted November 7, 2014 Hello sddenrweb, I think, you can try the following code: <script type="text/javascript"> function turnOffMix() { if (document.getElementById("InsertRecordmix").checked) { document.getElementById("InsertRecordmix").checked = false; } } function turnOffPure() { if (document.getElementById("InsertRecordpure").checked) { document.getElementById("InsertRecordpure").checked = false; } } document.getElementById("InsertRecordpure").onchange=turnOffMix; document.getElementById("InsertRecordmix").onchange=turnOffPure; </script> Quote Link to comment Share on other sites More sharing options...
SDDENR Posted November 7, 2014 Author Report Share Posted November 7, 2014 Hello sddenrweb, I think, you can try the following code: <script type="text/javascript"> function turnOffMix() { if (document.getElementById("InsertRecordmix").checked) { document.getElementById("InsertRecordmix").checked = false; } } function turnOffPure() { if (document.getElementById("InsertRecordpure").checked) { document.getElementById("InsertRecordpure").checked = false; } } document.getElementById("InsertRecordpure").onchange=turnOffMix; document.getElementById("InsertRecordmix").onchange=turnOffPure; </script> Thank you Caspio Guru! I tried it and It works perfectly fine -- should have realized some sort of triggering event would be needed. Quote Link to comment Share on other sites More sharing options...
RuisiHansamu Posted August 16, 2023 Report Share Posted August 16, 2023 Hi! just wanted to share or add this forum post as well that might help you out Quote Link to comment Share on other sites More sharing options...
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.