Using Bootbox Confirm, where to place preventDefault?2019 Community Moderator ElectionWhere should I put <script> tags in HTML markup?Bootbox callback not working properlyJavascript Confirm box working wrongTwitterBootStrap Submit Button still submits the formReplace JavaScript confirm alert with bootbox.js confirmRails delete link call from javascriptbootbox giving DOM selection troubleBootbox dialog doesn't open within a loopBootbox callback function not being calledbootbox.confirm dose not display the message and page crashed

Math equation in non italic font

Calculate the frequency of characters in a string

What is the meaning of まっちろけ?

What do you call a language that doesn't use the European alphabet?

While on vacation my taxi took a longer route, possibly to scam me out of money. How can I deal with this?

Have the tides ever turned twice on any open problem?

World War I as a war of liberals against authoritarians?

Recruiter wants very extensive technical details about all of my previous work

Are ETF trackers fundamentally better than individual stocks?

Explaining pyrokinesis powers

TikZ node shape depends on inside text

How to make healing in an exploration game interesting

Did Ender ever learn that he killed those two boys?

How to fill the area between n intersecting points in TikZ

Why is a white electrical wire connected to 2 black wires?

Is it normal that my co-workers at a fitness company criticize my food choices?

Why is there is so much iron?

Non-trivial topology where only open sets are closed

What does this 切 mean here?

How could an airship be repaired midflight?

Is there a hypothetical scenario that would make Earth uninhabitable for humans, but not for (the majority of) other animals?

Brexit - No Deal Rejection

How could a scammer know the apps on my phone / iTunes account?

Happy pi day, everyone!



Using Bootbox Confirm, where to place preventDefault?



2019 Community Moderator ElectionWhere should I put <script> tags in HTML markup?Bootbox callback not working properlyJavascript Confirm box working wrongTwitterBootStrap Submit Button still submits the formReplace JavaScript confirm alert with bootbox.js confirmRails delete link call from javascriptbootbox giving DOM selection troubleBootbox dialog doesn't open within a loopBootbox callback function not being calledbootbox.confirm dose not display the message and page crashed










0















I have a basic web page, MVC with jQuery and Bootbox, when the user clicks on a delete link I would like to display a confirmation box, yes -or- no and then preventDefault or return false based on the answer. Pretty simple stuff but I can't seem to capture the result value from BootBox.



The HTML snippet



@Html.ActionLink("Delete", "Delete", new id = item.UserDetailId , 
new @class = "delete_click", onclick = "return ConfirmDelete('" + item.Email + "');" )


The Javascript



var confirm_result = false;

function ConfirmDelete(message)
bootbox.confirm(
message: "<h3>Delete this account:</h3> <span class=bold> " + message + " </span>",
buttons:
cancel:
label: 'No'
,
confirm:
label: 'Yes'

,
callback: function(result)
console.log('This was logged in the callback: ' + result);
confirm_result = result;

);
// ?? how do I control the true/false return value here ??
return false;
;




Everything works, no errors, dialog is displayed, callback is called, etc; but the confirm_result does not get set to true when the user clicks OK?



Do I need to split the callback to a separate function?



UPDATE: The callback is asynchronous! The ConfirmDelete function always exits before the callback has been executed! That's my problem, working on a fix ....










share|improve this question




























    0















    I have a basic web page, MVC with jQuery and Bootbox, when the user clicks on a delete link I would like to display a confirmation box, yes -or- no and then preventDefault or return false based on the answer. Pretty simple stuff but I can't seem to capture the result value from BootBox.



    The HTML snippet



    @Html.ActionLink("Delete", "Delete", new id = item.UserDetailId , 
    new @class = "delete_click", onclick = "return ConfirmDelete('" + item.Email + "');" )


    The Javascript



    var confirm_result = false;

    function ConfirmDelete(message)
    bootbox.confirm(
    message: "<h3>Delete this account:</h3> <span class=bold> " + message + " </span>",
    buttons:
    cancel:
    label: 'No'
    ,
    confirm:
    label: 'Yes'

    ,
    callback: function(result)
    console.log('This was logged in the callback: ' + result);
    confirm_result = result;

    );
    // ?? how do I control the true/false return value here ??
    return false;
    ;




    Everything works, no errors, dialog is displayed, callback is called, etc; but the confirm_result does not get set to true when the user clicks OK?



    Do I need to split the callback to a separate function?



    UPDATE: The callback is asynchronous! The ConfirmDelete function always exits before the callback has been executed! That's my problem, working on a fix ....










    share|improve this question


























      0












      0








      0








      I have a basic web page, MVC with jQuery and Bootbox, when the user clicks on a delete link I would like to display a confirmation box, yes -or- no and then preventDefault or return false based on the answer. Pretty simple stuff but I can't seem to capture the result value from BootBox.



      The HTML snippet



      @Html.ActionLink("Delete", "Delete", new id = item.UserDetailId , 
      new @class = "delete_click", onclick = "return ConfirmDelete('" + item.Email + "');" )


      The Javascript



      var confirm_result = false;

      function ConfirmDelete(message)
      bootbox.confirm(
      message: "<h3>Delete this account:</h3> <span class=bold> " + message + " </span>",
      buttons:
      cancel:
      label: 'No'
      ,
      confirm:
      label: 'Yes'

      ,
      callback: function(result)
      console.log('This was logged in the callback: ' + result);
      confirm_result = result;

      );
      // ?? how do I control the true/false return value here ??
      return false;
      ;




      Everything works, no errors, dialog is displayed, callback is called, etc; but the confirm_result does not get set to true when the user clicks OK?



      Do I need to split the callback to a separate function?



      UPDATE: The callback is asynchronous! The ConfirmDelete function always exits before the callback has been executed! That's my problem, working on a fix ....










      share|improve this question
















      I have a basic web page, MVC with jQuery and Bootbox, when the user clicks on a delete link I would like to display a confirmation box, yes -or- no and then preventDefault or return false based on the answer. Pretty simple stuff but I can't seem to capture the result value from BootBox.



      The HTML snippet



      @Html.ActionLink("Delete", "Delete", new id = item.UserDetailId , 
      new @class = "delete_click", onclick = "return ConfirmDelete('" + item.Email + "');" )


      The Javascript



      var confirm_result = false;

      function ConfirmDelete(message)
      bootbox.confirm(
      message: "<h3>Delete this account:</h3> <span class=bold> " + message + " </span>",
      buttons:
      cancel:
      label: 'No'
      ,
      confirm:
      label: 'Yes'

      ,
      callback: function(result)
      console.log('This was logged in the callback: ' + result);
      confirm_result = result;

      );
      // ?? how do I control the true/false return value here ??
      return false;
      ;




      Everything works, no errors, dialog is displayed, callback is called, etc; but the confirm_result does not get set to true when the user clicks OK?



      Do I need to split the callback to a separate function?



      UPDATE: The callback is asynchronous! The ConfirmDelete function always exits before the callback has been executed! That's my problem, working on a fix ....







      jquery bootbox






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 6 at 21:40









      marc_s

      581k13011221268




      581k13011221268










      asked Mar 6 at 21:10









      vscodervscoder

      1139




      1139






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I had forgotten how this works, the OnClick function calls the BootBox dialog which displays and then immediately exits. I return 'false' from the ConfirmDelete function to prevent the link from working. To submit the delete when the user clicks OK, I needed to redirect from inside the callback. The 'better' code looks like this.



           function ConfirmDelete(name, id) 
          bootbox.confirm(
          message: "Delete this user: " + name + "?",
          buttons:
          confirm:
          label: 'Yes'
          ,
          cancel:
          label: 'No'

          ,
          callback: function (result)
          if (result)

          var url = "Delete/" + id;
          console.log("redirect to url:" + url);
          window.location.href = url;

          else
          console.log("cancel delete");

          );
          return false;
          ;


          Note the window.location.href call, that was the key. There are other issues with managing a web page like this, managing the back button, etc; but this is working as expected.



          AJAX is your friend, learn to use AJAX!






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032200%2fusing-bootbox-confirm-where-to-place-preventdefault%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I had forgotten how this works, the OnClick function calls the BootBox dialog which displays and then immediately exits. I return 'false' from the ConfirmDelete function to prevent the link from working. To submit the delete when the user clicks OK, I needed to redirect from inside the callback. The 'better' code looks like this.



             function ConfirmDelete(name, id) 
            bootbox.confirm(
            message: "Delete this user: " + name + "?",
            buttons:
            confirm:
            label: 'Yes'
            ,
            cancel:
            label: 'No'

            ,
            callback: function (result)
            if (result)

            var url = "Delete/" + id;
            console.log("redirect to url:" + url);
            window.location.href = url;

            else
            console.log("cancel delete");

            );
            return false;
            ;


            Note the window.location.href call, that was the key. There are other issues with managing a web page like this, managing the back button, etc; but this is working as expected.



            AJAX is your friend, learn to use AJAX!






            share|improve this answer





























              0














              I had forgotten how this works, the OnClick function calls the BootBox dialog which displays and then immediately exits. I return 'false' from the ConfirmDelete function to prevent the link from working. To submit the delete when the user clicks OK, I needed to redirect from inside the callback. The 'better' code looks like this.



               function ConfirmDelete(name, id) 
              bootbox.confirm(
              message: "Delete this user: " + name + "?",
              buttons:
              confirm:
              label: 'Yes'
              ,
              cancel:
              label: 'No'

              ,
              callback: function (result)
              if (result)

              var url = "Delete/" + id;
              console.log("redirect to url:" + url);
              window.location.href = url;

              else
              console.log("cancel delete");

              );
              return false;
              ;


              Note the window.location.href call, that was the key. There are other issues with managing a web page like this, managing the back button, etc; but this is working as expected.



              AJAX is your friend, learn to use AJAX!






              share|improve this answer



























                0












                0








                0







                I had forgotten how this works, the OnClick function calls the BootBox dialog which displays and then immediately exits. I return 'false' from the ConfirmDelete function to prevent the link from working. To submit the delete when the user clicks OK, I needed to redirect from inside the callback. The 'better' code looks like this.



                 function ConfirmDelete(name, id) 
                bootbox.confirm(
                message: "Delete this user: " + name + "?",
                buttons:
                confirm:
                label: 'Yes'
                ,
                cancel:
                label: 'No'

                ,
                callback: function (result)
                if (result)

                var url = "Delete/" + id;
                console.log("redirect to url:" + url);
                window.location.href = url;

                else
                console.log("cancel delete");

                );
                return false;
                ;


                Note the window.location.href call, that was the key. There are other issues with managing a web page like this, managing the back button, etc; but this is working as expected.



                AJAX is your friend, learn to use AJAX!






                share|improve this answer















                I had forgotten how this works, the OnClick function calls the BootBox dialog which displays and then immediately exits. I return 'false' from the ConfirmDelete function to prevent the link from working. To submit the delete when the user clicks OK, I needed to redirect from inside the callback. The 'better' code looks like this.



                 function ConfirmDelete(name, id) 
                bootbox.confirm(
                message: "Delete this user: " + name + "?",
                buttons:
                confirm:
                label: 'Yes'
                ,
                cancel:
                label: 'No'

                ,
                callback: function (result)
                if (result)

                var url = "Delete/" + id;
                console.log("redirect to url:" + url);
                window.location.href = url;

                else
                console.log("cancel delete");

                );
                return false;
                ;


                Note the window.location.href call, that was the key. There are other issues with managing a web page like this, managing the back button, etc; but this is working as expected.



                AJAX is your friend, learn to use AJAX!







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 6 at 23:15

























                answered Mar 6 at 23:05









                vscodervscoder

                1139




                1139





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032200%2fusing-bootbox-confirm-where-to-place-preventdefault%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                    Алба-Юлія

                    Захаров Федір Захарович