#itsm Disable submit button when none of checkbox are selected

Ankit Raj
Tera Contributor

On using a variable check box via a variable set, 3 checkbox are there, if none of the check box are selected user should not be able to submit the request and alert message should be there on top.

I was able to sort the alert part but it seems now it is not allowing to raise a request even if I select all check boxes or any.

 

function onSubmit() {
if
(g_form.getValue('checkbox_1) != '') || ('checkbox_2) != '') || (checkbox_3) != '')) {
alert("Please select at least one option to submit request");
return false;
}
else{
return true;
}

1 ACCEPTED SOLUTION

Vishwa Pandya19
Mega Sage

Hello Ankit,

 

Please use below script

function onSubmit() {
   //Type appropriate comment here, and begin script below

if(g_form.getValue('checkbox1') == 'false' && g_form.getValue('checkbox2') == 'false' && g_form.getValue('checkbox3') == 'false') {
	alert("Please select at least one option to submit request");
	return false;
}
else{
	return true;
}
}

Since they are checkboxes they will always give true or false as an answer.
Also we only want to restrict submission if none of them are checked. So instead of using "or" condition you need to use the "and" condition.

 

This will allow submission even if 1 checkbox is ticked as the condition won't be satisfied.

 

 

If my answer helps you in any way please mark it as correct or helpful.

View solution in original post

4 REPLIES 4

Vishwa Pandya19
Mega Sage

Hello Ankit,

 

Please use below script

function onSubmit() {
   //Type appropriate comment here, and begin script below

if(g_form.getValue('checkbox1') == 'false' && g_form.getValue('checkbox2') == 'false' && g_form.getValue('checkbox3') == 'false') {
	alert("Please select at least one option to submit request");
	return false;
}
else{
	return true;
}
}

Since they are checkboxes they will always give true or false as an answer.
Also we only want to restrict submission if none of them are checked. So instead of using "or" condition you need to use the "and" condition.

 

This will allow submission even if 1 checkbox is ticked as the condition won't be satisfied.

 

 

If my answer helps you in any way please mark it as correct or helpful.

Thanks Vishwa, much appreciated.

Kavita_Bhojane
Tera Guru

Hi @Ankit Raj ,

Please make use of below script:

 

function onSubmit() {

var checkbox_1 =  g_form.getValue('checkbox_1');

var checkbox_2 =  g_form.getValue('checkbox_2');

var checkbox_3 =  g_form.getValue('checkbox_3');

if((checkbox_1 == 'false') && (checkbox_2 == 'false') && (checkbox_3 == 'false')) {
alert("Please select at least one option to submit request");
return false;
}
else{
return true;
}

}

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Kavita Bhojane

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @Ankit Raj 

 

Create a Onsubmit catalog client script in the variable set were you have the 3 check boxes. Use the below script.

 

function onSubmit() {

if(g_form.getValue('checkbox_var1') == 'false' && g_form.getValue('checkbox_var2') == 'false' && g_form.getValue('checkbox_var3') == 'false')
{
alert("your alert message here........................");
return false;
}
else
{
return true;
}
}

☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect