How to make multiple "checkbox" variables mandatory.........

ID NOBLE
Tera Expert

Hello,

 

Please how can I make multiple "checkbox" variables mandatory on a request form. Basically, there are about 6 checkbox variables and each of them must equal to "TRUE" for the form to be submitted. If one or two of those checkbox are not checked, the system must not allow submission until they are all checked. How do I do this please?

 

Thanks in advance.

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@ID NOBLE 

something like this in onSubmit catalog client script

function onSubmit() {
    // List your checkbox variable names here
    var checkboxes = [
        'checkbox_var_1',
        'checkbox_var_2',
        'checkbox_var_3',
        'checkbox_var_4',
        'checkbox_var_5',
        'checkbox_var_6'
    ];

    // Check if all are true (checked)
    for (var i = 0; i < checkboxes.length; i++) {
        if (g_form.getValue(checkboxes[i]).toString() !== 'true') {
            alert('Please check all required checkboxes before submitting.');
            return false; // block submission
        }
    }

    return true; // all checked, allow submit
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

Thanks for your supports. However, I have tried it but it doesn't work please. Is there any other way we can make it work please?

Thanks

@ID NOBLE 

script I shared should work fine and will check if all checkboxes are true or not

what debugging did you do?

did you replace your variable names in that above script?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar ,

 

Yes, I replaced the names in the script above with the actual variable names.