quickjava
asked on
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:
$(document).ready(function (){
var message ='Confirm Delete? ';
alert("inside close");
if(!message){return}
var title = $('form').attr('data-Close Title');
var cancelLabel = $('form').attr('data-Close CancelLabe l');
var confirmLabel = $('form').attr('data-Close ConfirmLab el');
var confirmMessage = $('form').attr('data-Close ConfirmMes sage');
// 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.
$(document).ready(function
var message ='Confirm Delete? ';
alert("inside close");
if(!message){return}
var title = $('form').attr('data-Close
var cancelLabel = $('form').attr('data-Close
var confirmLabel = $('form').attr('data-Close
var confirmMessage = $('form').attr('data-Close
// 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',
alert("inside function");
e.preventDefault();
var link = $( this ).attr('data-CloseLink');
var dialogButtons = {};
dialogButtons[cancelLabel]
dialogButtons[confirmLabel
$('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
</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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
$('#biller').bind('click',
$(document).ready(function
$('#biller').trigger('clic
});