javascriptjquerymodal-dialogblockui

How to prevent closing blockUI if there is input on textarea


Please I need your help in this.. I have built a $.blockUI modal and I have an 'X' button to close it. On button click, if there is some value on textarea I want to display a message that there is input and prevent closing the modal.Any ideas how can I do this?

close_modal function:

function close_modal(event){
      $.unblockUI();
         if (document.getElementById("comments").value.length > 0){
         alert("There is input!");

         //Here must be the code to prevent closing modal
           .
           .
           .
         //End of code

         }
      }

Solution

  • You can try something like this

    function close_modal(event){
      if (document.getElementById("comments").value.length > 0){
          if(confirm("There is input!")) $.unblockUI();
      } else $.unblockUI();
    }