OnSubmit: I need to display an alert if the checkbox is not checked.

Sonu Singh
Mega Expert

HI All,

If a User doesn't check the checkbox then on Submit of catalog request I need to display an alert.

find_real_file.png

if the user click on OK then request has to be submitted, if the clicks on Cancel then he has to stay back on the form.

With the below script, in both the case form is not getting submitted.

Script:

function onSubmit() {
var checkboxResponse= g_form.getValue('chkbox_verify');
if(checkboxResponse=='false'){
if(confirm('You Have not checked the verification..\n\nPlease press [OK] to continue.')=='true'){
//request has to be submitted.
return true;
}
else{
//Stay back on the form.
g_form.setValue('chkbox_verify', false);
return false;
}
}
}

 

Can someone help me on this.

Thanks

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

Try this. 

function onSubmit() {
var checkboxResponse= g_form.getValue('chkbox_verify');

 if(checkboxResponse=='false' || checkboxResponse== false ){

  var val=confirm("You Have not checked the verification..\n\nPlease press [OK] to continue.");
  if(val){
  //request has to be submitted.
   return true;
  }
  else{

  g_form.setValue('chkbox_verify', false);
  return false;
  }
 }
}

 

Please mark this correct & helpful if it answered your question.

Thanks & Regards,
Sharjeel

Regards,
Muhammad

View solution in original post

8 REPLIES 8

Pratiksha Kalam
Kilo Sage

Hello,

Checkbox always return true value,

var checkMod = g_form.getValue('u_modify_text')); //checkMod is true if u_modify_text is checked, false if unchecked

if (checkMod){
}

OR
function onSubmit() {
	
	

		
		
		var checkboxes = ['checkbox1', 'checkbox2', 'checkbox3', 'checkbox4'];
		var isSelected = false;
		
		for (var i = 0; i < checkboxes.length; i++) {
			
			if (g_form.getValue(checkboxes[i]) == 'true') {
				isSelected = true;
				break;
			}
		}
		
		if (isSelected == false) {
			g_form.addErrorMessage('At least one  checkbox is required');
			
			return false;
		}
		
	
	
}
If answer is helpful mark correct!
Thanks,
Pratiksha

Dhananjay Pawar
Kilo Sage

Hi,

try this script.

function onSubmit() {
var checkboxResponse= g_form.getValue('chkbox_verify');
if(checkboxResponse=='false'){

var val=confirm("You Have not checked the verification..\n\nPlease press [OK] to continue.");
if(val=='true'){
//request has to be submitted.
return true;
}
else{
//Stay back on the form.
g_form.setValue('chkbox_verify', false);
return false;
}
}
}

Thanks,

Dhananjay.

Hi Sonu,

Did you find any error in my code?

Thanks,

Dhananjay.

MrMuhammad
Giga Sage

Try this. 

function onSubmit() {
var checkboxResponse= g_form.getValue('chkbox_verify');

 if(checkboxResponse=='false' || checkboxResponse== false ){

  var val=confirm("You Have not checked the verification..\n\nPlease press [OK] to continue.");
  if(val){
  //request has to be submitted.
   return true;
  }
  else{

  g_form.setValue('chkbox_verify', false);
  return false;
  }
 }
}

 

Please mark this correct & helpful if it answered your question.

Thanks & Regards,
Sharjeel

Regards,
Muhammad