We help IT Professionals succeed at work.

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

quickjava
quickjava asked
on
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:

$(document).ready(function(){
      var message ='Confirm Delete? ';
      alert("inside close");
          if(!message){return}
          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");
                e.preventDefault();
              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
              .dialog({
                resizable: false,
                draggable: false,
                show: 'drop',
                hide: 'drop',
                width:500,
                height:200,
                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}">
          <script>
               $("button:biller").trigger('click');
          </script>
        </c:if>

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.
Comment
Watch Question

Commented:
wrap it like

<script>
     $(function() {
         $("button:biller").trigger('click');
     }
</script>
Kiran SonawaneProject Lead
Top Expert 2011

Commented:
OR

  $(document).ready(function(){
   $('#biller').trigger('click');
});

Author

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.