We help IT Professionals succeed at work.

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

quickjava asked
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.
Watch Question

wrap it like

     $(function() {
Kiran SonawaneProject Lead
Top Expert 2011




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.