Need help with a button & javascript

  • 1
  • 2
  • Question
  • Updated 2 years ago
  • In Progress
  • (Edited)
I've made a button that does the following:
1) calls a javascript function
2) that shows a pop-up requesting a value
3) that when entered, executes an API_Edit
4) that pastes the entered value into a field.

That works, fine, but when I click cancel on the popup (say I clicked it by mistake) the API still executes, writing "null" in the field.

I've tried many approaches but, not being very proficient in javascript, I have no idea how validate the "OK" or "CANCEL" clicks in the popup and stop the API Execution.

Some of this code is based off Dan Diebold's code (which I can't find the post for, and I'll link it as soon as I do)

The button contains the following:

"javascript:" &
"var QBU_rid = '" & [Record ID#] & "';" &
"var QBU_Date_Created = '" & ToDate([Date Created]) & "';" &
"$.getScript(gReqAppDBID + '?a=dbpage&pagename=buttonscript.js');" &

And then there's the Javascript page:

var apptoken = "####@@@@#####@@@#@#@#@#@.";
$.ajaxSetup({data: {apptoken: apptoken}});
 var numdua = prompt("Type in the number: ");
 var fecha = new Date ();
 var promise = $.get(gReqDBID,{
  act: "API_EditRecord",
  rid: QBU_rid,
  _fid_8: numdua,
  _fid_11: fecha
  document.location.href = gReqDBID + "?a=dr&rid=" + QBU_rid;

Photo of Carlos


  • 776 Points 500 badge 2x thumb

Posted 2 years ago

  • 1
  • 2
Photo of John Thomas

John Thomas

  • 1,082 Points 1k badge 2x thumb
Just write a if  else condition, Just modifying  the code 
 var numdua = prompt("Type in the number: ");
 if(numdua == null){
   alert("No Data"); // there will be no value entered to the record
  var promise = $.get(gReqDBID,{
  act: "API_EditRecord",
  rid: QBU_rid, _fid_8: numdua });