Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8679947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:07:18+00:00 2026-06-12T21:07:18+00:00

I have a jquery mobile dialog that confirms if the user wants to overwrite

  • 0

I have a jquery mobile dialog that confirms if the user wants to overwrite a file that they upload. If the user clicks yes, then the callback function to upload is called, and if they click no then the dialog closes and nothing happens.

The problem is that if they user clicks no, and then clicks to upload again and accepts the overwrite, it calls the callback function twice. It is building up the callbacks depending on how many time they enter the dialog state and I am not sure how to handle this.

This is the entry point everytime the user clicks “upload”

CheckOverwriteUpload: function (boxFolderId, fileName) {
            var matchFound = false;
            $.each(BoxManager.Entries, function (index, value) {
                var entry = value;
                if (entry.name == fileName) {
                    matchFound = true;//Found the matching file
                }
            })


            if (matchFound) {
                //Pop the dialog to ask if they want to overwrite the file
                areYouSure("Overwrite File?", "The file " + fileName + " Already exists, would you like to overwrite it?", "Yes", function (result) {
                    if (result == true) {
                        //The client wants to overwrite the file, so we upload it
                        BoxManager.UploadFile(boxFolderId, fileName, true);

                    } else {
                        //The client does not want to overwrite. Close the dialog
                        $("#sure").dialog('close');
                    }
                    //Placed here to close the dialog after the possible upload
                    $("#sure").dialog('close');

                });
            } else {
                //No matches, go ahead and upload
                BoxManager.UploadFile(boxFolderId, fileName, matchFound);
            }

        },

Here is the dialog function

function areYouSure(text1, text2, button, callback) {

        $("#sure .sure-1").text(text1);
        $("#sure .sure-2").text(text2);
        $("#sure .sure-do").text(button).on("click", function () {
            callback(true);
        });
        $("#sure .close-do").text("No").on("click", function () {
            callback(false);
        });
        $.mobile.changePage("#sure", 'none', false, true);
    }

And just in case it is needed, here is the upload code. It just calls a method on the server

UploadFile: function (boxFolderId, fileName, overWrite) {
            $.mobile.showPageLoadingMsg();
            var etag = "";
            var id = "";
            $.each(BoxManager.Entries, function (index, value) {
                var entry = value;
                if (entry.name == fileName) {
                    etag = entry.etag;//hash of file used to overwrite files on box.com
                    id = entry.id;//unique box id for file. needed to overwrite file
                }
            });
            DocumentVaultService.UploadFileToBox(
                                        "<%=RootFolderGuid %>",
                                        "<%=FolderGuid %>",
                                        "<%=FileGuid %>",
                                        boxFolderId,
                                        fileName,
                                        "<%=IsClientFolder%>",
                                        "<%=AuthToken %>",
                                        overWrite,
                                        etag,
                                        id,
                                        function (result) {
                                            //Success on the upload, refresh the document list and close loading symbol
                                            BoxManager.GetBoxFolderContent(boxFolderId, BoxManager.BreadCrumbList[length - 1].folderName);
                                            $.mobile.hidePageLoadingMsg();
                                        },
                                        function (result) {

                                            $.mobile.hidePageLoadingMsg();
                                            alert("File failed to upload");
                                        });


        }

CheckOverwriteUpload and UploadFile are both contained in Boxmanager like so

var BoxManager = {
    CheckOverwriteUpload:function(){},
    UploadFile:function(){}
}

How can I prevent this from calling multiple times? Is there a way to clear the javascript cache before I call the dialog? Is there a better structure that I am not seeing for the callbacks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:07:19+00:00Added an answer on June 12, 2026 at 9:07 pm

    Every time you call areYouSure() it is binding the callbacks again. One way around this is to unbind, then bind:

    $("#sure .close-do").text("No").unbind("click").on("click", function () {
        callback(false);
    });
    

    Notice the unbind("click"). This removes any previous bindings, so they won’t stack up.
    Another way around this is to put the Yes/No button bindings somewhere else that only gets called once (like the pageinit).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic jquery mobile modal dialog that INTERMITTENTLY reloads on clicking
I have a link that create a dialog with jquery mobile in my page
I have a code in jquery mobile that will add buttons dynamically in a
In jQuery Mobile I have several chained dialog boxes sliding in/out one after another
I have created app using jQuery Mobile and need to get a Dialog box
I have a mobile page, that opens a dialog. In the dialog, there is
I have jQuery mobile working with google maps so that I can display one,
Throughout a jQuery mobile site I am working on I have anchor tags that
I have JQuery Mobile-1.0.js file. // Load a page into the DOM. $.mobile.loadPage =
I have a jquery mobile page that uses the following code to hide a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.