Coolguy Coolguy - 1 year ago 98
CSS Question

Javascript bootstrap modal calling function

My code is like below:

function OnApply(runFunc) {
$("#myCfmModal").find("#myCfmModalText").html("Apply change now?");
$("#myCfmModal").one('click', '#okbtn', runFunc);

function cool() {

I have a problem running the code above. I call the
as below:

<button class="btn btn-success" onclick="OnApply(cool())">Apply</button>

will show a modal box and run a function
. What I want to do is to run function
when I click the OK button in the modal box. However the
function will always run first before I click the OK button. Any idea what went wrong?

Answer Source

The issue is because you are passing the result of the cool() function to OnApply() - you instead need to pass the reference to the function by removing the trailing brackets. Try this:

<button class="btn btn-success" onclick="OnApply(cool)">Apply</button>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download