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

Hi,

can we hide the alert if the particular check is not displayed on the form?

Thanks

Hi Sonu, 

 

When you say Particular check, do you mean any other checkbox field is not checked or the field is not available on the form? 

 

Thanks & Regards,

Sharjeel 

Regards,
Muhammad

Chander Bhusha1
Tera Guru

Use can use the same code with few changes just remove =='true' part from confirm box and it will work.

Just one line change on confirm box

 

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.')){
return true;
}
else{
g_form.setValue('chkbox_verify', false);
return false;

}
}
}
	

Mark helpful and correct.

Thanks,

CB

Mohammad Danis1
Giga Guru

Hi Sonu,

Please find the updated script :

function onSubmit() {
var checkboxResponse = g_form.getValue('chkbox_verify');
if(checkboxResponse == 'false' || checkboxResponse == false){
var res = confirm('You Have not checked the verification..\n\nPlease press [OK] to continue.');
if(res){
return true;
}
else{
  return false;
  }
 }
}

As you already checked that "chkbox_verify" is false, no need to set it again as false.

 

Please consider marking appropriate reply as Correct & 👍Helpful .

Kind Regards,
Mohammad Danish