- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 08:18 AM
Hello. We have a catalog item for users to request access using checkbox variables. The user can select one checkbox or multiple.
The requirement is to send the label/name of the selected checkboxes in a comma separated string in an existing REST API.
My challenge is around arrays. How do I loop through the checkboxes that were selected to create a single comma separated list?
Example 1: Both checkboxes were selected, the string value should be "AuditBoard,BOX"
Example 2: One checkbox was selected, the string value should be "BOX"
Thank you for your help.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 08:34 AM - edited 08-20-2024 08:35 AM
@heathers_ You can try the following onLoad script and form an array of selected checkbox label.
Let's say you have the following checkbox fields:
- u_checkbox_1
- u_checkbox_2
- u_checkbox_3
function onSubmit() {
var selectedValues = []; // Array to store selected checkbox values
// Check each checkbox field and add its value to the array if it is checked
if (g_form.getValue('u_checkbox_1') == 'true') {
selectedValues.push(g_form.getLabelOf('u_checkbox_1')); // Push the label or value
}
if (g_form.getValue('u_checkbox_2') == 'true') {
selectedValues.push(g_form.getLabelOf('u_checkbox_2'));
}
if (g_form.getValue('u_checkbox_3') == 'true') {
selectedValues.push(g_form.getLabelOf('u_checkbox_3'));
}
// Join the array into a single comma-separated string
var selectedValuesString = selectedValues.join(', ');
// Set the value of the target field with the comma-separated list
alert(selectedValuesString);
return true; // Allow the form submission to proceed
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 08:34 AM - edited 08-20-2024 08:35 AM
@heathers_ You can try the following onLoad script and form an array of selected checkbox label.
Let's say you have the following checkbox fields:
- u_checkbox_1
- u_checkbox_2
- u_checkbox_3
function onSubmit() {
var selectedValues = []; // Array to store selected checkbox values
// Check each checkbox field and add its value to the array if it is checked
if (g_form.getValue('u_checkbox_1') == 'true') {
selectedValues.push(g_form.getLabelOf('u_checkbox_1')); // Push the label or value
}
if (g_form.getValue('u_checkbox_2') == 'true') {
selectedValues.push(g_form.getLabelOf('u_checkbox_2'));
}
if (g_form.getValue('u_checkbox_3') == 'true') {
selectedValues.push(g_form.getLabelOf('u_checkbox_3'));
}
// Join the array into a single comma-separated string
var selectedValuesString = selectedValues.join(', ');
// Set the value of the target field with the comma-separated list
alert(selectedValuesString);
return true; // Allow the form submission to proceed
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 08:41 AM