Catalog item variable checkbox there are two option but only one should be selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 08:01 AM
I tried to use the UI action to select a mandatory filed and applying the label to be set as a mandatory filed but i cannot able to achieve my condition form is getting submitted if both checkbox are selected.
Tried creating a below catalog script its also not working
function onSubmit() {
var checkboxes = ['box1', 'box2'];
var selectedCount = 0;
for (var i = 0; i < checkboxes.length; i++) {
if (g_form.getValue(checkboxes[i]) == 'true') {
selectedCount++;
}
}
if (selectedCount !== 1) {
g_form.addErrorMessage('Please select only one checkbox.');
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 08:18 AM
why cant you use multiple choice field? which will give option as radio button and allow only to select one option?
Thanks
Harshad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 08:20 AM
Hi,
Are you getting the Error message you have added in your script?
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 08:22 AM
Hi,
Please try below:
function onSubmit() {
var checkboxes = ['box1', 'box2'];
var selectedCount = 0;
for (var i = 0; i < checkboxes.length; i++) {
if (g_form.getValue(checkboxes[i]) == 'true') {
selectedCount++;
}
}
if (selectedCount != 1) {
g_form.addErrorMessage('Please select only one checkbox.');
return false;
}
}
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 08:25 AM
Hello @Bobby8
function onLoad(){
var chk1 = g_form.getControl('chkfield1_name');
var chk2 = g_form.getControl('chkfield2_name');
var count = 0;
If(chk1.checked){
count++;
}
If(chk2.checked){
count++;
}
if(count==1){
return true;
}
else{
return false;
}
}
Plz use this script :-
Mark my solution as Accept if you find it helpful.
Regards
SAMAKSH