How to trigger a Jquery function based on a boolean flag value from JSP

I am going some validation in my Action class and returning some flag to JSP. Based on the Flag value, I need to trigger the JQuery function to create some popup window.  Here is my Jquery script:

      var message ='Confirm Delete? ';
      alert("inside close");
          var title = $('form').attr('data-CloseTitle');
          var cancelLabel  = $('form').attr('data-CloseCancelLabel');
          var confirmLabel = $('form').attr('data-CloseConfirmLabel');
          var confirmMessage = $('form').attr('data-CloseConfirmMessage');
          // Default labels for dialog
          if(!title) { title = 'Close Approval'; }
          if(!cancelLabel) { cancelLabel = 'No'; }
          if(!confirmLabel) { confirmLabel = 'Yes, continue.'; }
          if(!confirmMessage) { confirmMessage = 'approval is required. Do you want to send this to close'; }
          $('#biller').bind('click', function(e){
                alert("inside function");
              var link = $( this ).attr('data-CloseLink');
              var dialogButtons = {};
              dialogButtons[cancelLabel] = function(){ $( this ).dialog('close'); }
              dialogButtons[confirmLabel] = function(){  $( this ).dialog('close');
              $('form').attr('action', link);
              $("form").submit(); }
              $('<div id="dialog-confirm" title="'+ title +'">'+ confirmMessage +'</div>') // Create dialog
                resizable: false,
                draggable: false,
                show: 'drop',
                hide: 'drop',
                modal: true,
                buttons: dialogButtons
              return e;

Here is my JSP, I am trying to trigger the Jquery based on the flag:
<c:if test="${sendToclose}">

But the jquery is not triggering and popup is not coming. Please let me know the problem here or any suggestions to trigger the jquery based on the flag value only.
Who is Participating?
baretreeConnect With a Mentor Commented:
wrap it like

     $(function() {
Kiran SonawaneProject LeadCommented:

quickjavaAuthor Commented:
Thanks and it is working. But actually I don't want any button on the screen to trigger this.  I want to trigger the Jquery when the flag is true.  Currently I binded the jquery using the button click .
 $('#biller').bind('click', function(e){ } But I don't want any button on the screen and I need to trigger it when the flag is true.  How to bind this in jquery instead of button click.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.