How can I rewrite the below function such that it returns true/false only after one of the buttons is clicked?
function something(param){
var returnValue = false;
$('.btn-ok').on('click', function(){
returnValue = false;
});
$('.btn-cancel').on('click', function(){
returnValue = true;
})
return returnValue;
}
The problem currently is return returnValue;
executes as soon as this function is called but I want to wait for it to set returnValue
based on the button click.
UPDATE:
Apologies. I thought the above explanation of what I'm trying to do would be sufficient.
I am using Bootstrap modal box with jQuery as front end and JSF/Java in the backend. I have an inline click event which looks like this
onclick="if (!changeListner()) return false;"
for a link. This is to override the JSF inline click event. So this has to be there. The changeListener()
looks as such
function changeListener(){
if(formChanged){ //formChanged is a variable that is set to true when an input value changes
return something(param);
}
return true;
}
something(param)
is actually a dialog box setter that shows different messages based on the parameter. I am trying to pass true to the inline click event if the user chooses to hit "Cancel" or block the click event if the user chooses "Ok".