Client Script: Pop up confirmation on Field Change

Scott29
Kilo Sage

I currently have a very basic client script that confirms a field change (Script Below). Is there a way if they select cancel on the prompt, it reverts the field value to what it was before?

 

function onSubmit() {
    var legal = g_form.getValue('legal_review');
    if (legal =='No'){
      return;
  }
  var answer = confirm("Are you sure you want to set a Legal Review?");
    if (legal =='Yes'){
      // User clicked Cancel, prevent the form from being saved
      return false;
  }
}
2 REPLIES 2

AshishKM
Kilo Patron
Kilo Patron

Hi @Scott29

You can use hidden variable and copy the previous value and use that same in case of "Cancel".

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Bert_c1
Kilo Patron

the following script may get you the behavior you want.

 

function onSubmit() {
   //Type appropriate comment here, and begin script below
    var legal = g_form.getValue('u_legal_review');
	alert('u_legal_review = ' + legal);
	if (legal =='No'){
    	return;
  	}
	return confirm(getMessage('Are you sure you want to set a Legal Review?'));
	//  var answer = confirm("Are you sure you want to set a Legal Review?");
	//  if (legal =='Yes') {
      		// User clicked Cancel, prevent the form from being saved
	//      return false;
	//  }
}