Discussions

 View Only
  • 1.  Implement a rule in javascript if user clicks cancel on prompt

    Posted 06-01-2018 03:10
    Is there a way to implement a rule in javascript which will cancel running the code if user clicks cancel on a prompt window within the code?

    Thanks


  • 2.  RE: Implement a rule in javascript if user clicks cancel on prompt

    Posted 06-01-2018 17:55
    Something as simple as this will work:
    if(confirm("Do you want to continue?")) {
      //run code
    }
    If you want a better dialog box and more options used jQueryUI Dialog as shown in this demo:

    https://haversineconsulting.quickbase.com/db/bkw2ff3e3?a=q&qid=1


  • 3.  RE: Implement a rule in javascript if user clicks cancel on prompt

    Posted 06-01-2018 18:17
    Thanks Dan!

    I am doing this in myCript page.

    I have a prompt:

    var description= prompt("Enter a brief description of the work done in this session: ", "");

    if the user cancels within the prompt window then don't want to run the code. I tried putting the if statement but it does not seem to work:

    See in bold what I added

    (function(){
      var dbid = "bnqepesti";
      var dbidTable = dbid;
      var apptoken = "my app token";
      $.ajaxSetup({data: {apptoken: apptoken}});
      var description= prompt("Enter a brief description of the work done in this session: ", "");
      if(confirm("Do you want to continue?")) {
      var promise = $.get(dbidTable, {
        act: "API_EditRecord",
        rid: QBU_rid,
       _fid_20: description,
        _fid_6: "Out"
      }).then(function(xml) {
        console.dirxml(xml);
     $.get() & location.reload(true);
      });
    })();}


  • 4.  RE: Implement a rule in javascript if user clicks cancel on prompt

    Posted 06-03-2018 03:57
    I figured this out:

    I entered these lines of code after the prompt line:

      if (description == null || description == "")  {
      alert("You did not enter a description I will cancel this Time Out.");
      Return;
    }

    This will alert and cancel the rest of the code if the user clicks cancel or leaves it blank and clicks ok.

    I hope this can help others interested in implementing this in their apps.