Discussions

Expand all | Collapse all

Need help with a button & javascript

  • 1.  Need help with a button & javascript

    Posted 05-22-2017 18:10
    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');" &
    "void(0);"

    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
    });
    $.when(promise).then(function(){
      document.location.href = gReqDBID + "?a=dr&rid=" + QBU_rid;
    });



  • 2.  RE: Need help with a button & javascript

    Posted 05-23-2017 17:21
    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   }else{
      var promise = $.get(gReqDBID,{
      act: "API_EditRecord",
      rid: QBU_rid, _fid_8: numdua });