Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

devhoussam123's avatar

If input type file has a value show Confirmation message before closing the bootstrap modal dialog

Hello guys How are you I'm working now on a project and i Want to create a simple trick. I made a simple jQuery code but it still not working as I want. The whole story said : if input type file has a value show confirm message with yes or no before closing the modal so if the user want to leave the page and close the modal dialog it should show a confirmation message said if he is sure about closing the modal dialog....

HTML CODE :

<div class="modal fade" id="modal_a" tabindex="-1" role="dialog" aria-labelledby="modal_aLabel" aria-hidden="true"data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-body">
   <div class="uploadavatar">
        <input type="file" 
               class="custom-file-input" 
               id="ID12" 
               name="avatar"
               value=""
               hidden />
        <label role="button" class="btn" for="ID12">
            Upload Now
        </label>
    </div>
</div>
</div>
</div>
</div>
$(document).on('hide.bs.modal', '#test-modal', function(e) {
// 
});
0 likes
2 replies

Please or to participate in this conversation.