Skip to main content
Question

Confirm Popup and if ""OK"" execute API


Looking for URL/Java script code that will show a confirm popup and then execute an API (specifically an edit record) ONLY if OK was pressed. I have the popup and the API running, but I cannot get the API to run conditionally based on whether or not confirm is true or false. Any hints?
This topic has been closed for replies.

  • Registered
  • July 30, 2019
I could try and explain it but I think an example from somewhere else is probably the best. There are several ways but they all basically do the same thing, its more like explicit vs implicit.

var txt;
var r = confirm("Press a button!");
if (r == true) {
  txt = "You pressed OK!";
} else {
  txt = "You pressed Cancel!";
}

That is one way.

if (confirm("Press a button!")) {
  txt = "You pressed OK!";
} else {
  txt = "You pressed Cancel!";
}



There are more in the links below.

https://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm
Also this one https://www.w3schools.com/jsref/met_win_confirm.asp

  • Author
  • Registered
  • July 30, 2019
Thank you so much!, but I am trying to incorporate something like this: 

if (confirm("Are you sure you want to mark complete?")) {
  //(if yes) execute the api (which is sitting in a variable)
} else {
 // alert that record was not saved
}

Here is part of my code with the following variables  (it's all in a URL formula):

$popup: "javascript:confirm('...')
$url: the API that is editing the current record
$Cancel: "javascript:alert('....')

"javascript:" &
 "$.get('" & $popup & 
    "',function() {" &
    "if ($popup == true) {" &
     & $url & 
      "} else {"
 & $Cancel &
  "});" &
  "void(0);"

  • Author
  • Registered
  • July 30, 2019
Your examples are very helpful, I just can't seem to get it to work with another variable.