- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 02:52 AM
Hello,
I have 10 checkbox variables created we want users to select at least 1 checkbox otherwise it should throw an error.
How to acheive this
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 04:33 AM
I've used the below script in an onSubmit Client Script
function onSubmit(){
//Set the mandatory checkbox variable names and total mandatory count here
var mandatoryVars = '<checkbox values here seperated by a ,>';
var mandatoryCount = 1;
var passed = forceMandatoryCheckboxes(mandatoryVars, mandatoryCount);
if(!passed){
//Abort the submit
alert('You must select at least ' + mandatoryCount + ' options.');
return false;
}
}
function forceMandatoryCheckboxes(mandatory, count){
//Split the mandatory variable names into an array
mandatory = mandatory.split(',');
var answer = false;
var varFound = false;
var numTrue = 0;
//Check each variable in the array
for(x=0;x<mandatory.length;x++){
//Check to see if variable exists
if(g_form.getControl(mandatory[x])){
varFound = true;
//Check to see if variable is set to 'true'
if(g_form.getValue(mandatory[x]) == 'true'){
numTrue ++;
//Exit the loop if we have reached required number of 'true'
if(numTrue >= count){
answer = true;
break;
}
}
}
}
//If we didn't find any of the variables allow the submit
if(varFound == false){
answer = true;
}
//Return true or false
return answer;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 05:04 AM
One question Ian, can you please let me know the purpose of using ?
if(g_form.getControl(mandatory[x])){
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 05:16 AM
It's checking that you have an array value for 'mandatory'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 04:49 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 04:50 AM
hi
use this code
function onSubmit() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('u_test1') == "true" || g_form.getValue('u_test2') == "true" ||g_form.getValue('u_test3') == "true"||g_form.getValue('u_test4') == "true" || g_form.getValue('u_test6') == "true" ||g_form.getValue('u_test6') == "true" )
{
return true;
}
else
{
alert("Select the checkbox");
return false;
}
}
Thanks,
Rahul Kumar