- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2023 11:28 PM
Hi Team,
I have one requirement to select only 2checkboxes from 6 checkboxes in an order guide. I mean to restrict only 2checkboxes from 6 checkboxes in options as below using on submit client script?
If we select more than 2 checkboxes from the options, then it should display error message when submit. only 2 checkboxes from this should select. if more than that error msg should display. Please help anyone.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 12:25 AM
Hello @sree42
You need to write onSubmit() Client Script :-
function onSubmit(){
var chk1 = g_form.getControl('checkbox_1');
var chk2 = g_form.getControl('checkbox_2');
var chk3 = g_form.getControl('checkbox_3');
var chk4 = g_form.getControl('checkbox_4');
var chk5 = g_form.getControl('checkbox_5');
var chk6 = g_form.getControl('checkbox_6');
var arrchk = [chk1,chk2,chk3,chk4,chk5,chk6];
var count=0;
for(let i=0; i<arrchk.length; i++){
if(arrchk[i].getChecked){
count++;
}
}
if(count>2){
return false;
gs.info('your error msg')
}
}
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 12:25 AM
Hello @sree42
You need to write onSubmit() Client Script :-
function onSubmit(){
var chk1 = g_form.getControl('checkbox_1');
var chk2 = g_form.getControl('checkbox_2');
var chk3 = g_form.getControl('checkbox_3');
var chk4 = g_form.getControl('checkbox_4');
var chk5 = g_form.getControl('checkbox_5');
var chk6 = g_form.getControl('checkbox_6');
var arrchk = [chk1,chk2,chk3,chk4,chk5,chk6];
var count=0;
for(let i=0; i<arrchk.length; i++){
if(arrchk[i].getChecked){
count++;
}
}
if(count>2){
return false;
gs.info('your error msg')
}
}
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 12:42 AM
Hi Samaksh,
Will try this. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 12:57 AM - edited 08-21-2023 01:35 AM
Hi Samaksh,
Thanks for this code. This is not working as expected. But it is working in another way. Thank you!
function onSubmit(){
var chk1 = g_form.getValue('checkbox_1');
var chk2 = g_form.getValue('checkbox_2');
var chk3 = g_form.getValue('checkbox_3');
var chk4 = g_form.getValue('checkbox_4');
var chk5 = g_form.getValue('checkbox_5');
var chk6 = g_form.getValue('checkbox_6');
var arrchk = [chk1,chk2,chk3,chk4,chk5,chk6];
var count=0;
for(var i=0; i<arrchk.length; i++){
if (arrchk[i] == 'true') {
count++;
}
}
if(count>2){
g_form..addErrorMessage('error');
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 01:01 AM - edited 08-21-2023 01:03 AM
Hello @sree42
Plz Mark my Solution as Accept and Give me thumbs up, As you find it helpful. it will help future members.
Regards,
Samaksh