Search code examples
javascriptjquerytwitter-bootstrapjspbootbox

How to pass value to bootbox alert function in jsp


Hello I am using bootbox for the first time. I need to pass some value to bootbox alert function. The following is my code

Calling Bootbox alert

<a class="alert" href=#><img alt="Solution" src="images/bulb.png" title="${listValue.solution }"></a>

Bootbox function code

<!-- JS dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>

<!-- bootbox code -->
<script src="js/bootbox.min.js"></script>
<script>
    $(document).on("click", ".alert", function(e) {
        bootbox.alert("Hello", function() {
            console.log("Alert Callback");
        });
    });
</script>

It is working fine. When i click on image it is showing alert box with "Hello" message which is fantastic.

My requirement is I need to pass some value(${listValue.solution } instead of "Hello") to bootbox funtion.

Please help me in achieving this. Thanks a lot in advance.


Solution

  • Why not pass the value to a variable?

    var msg = '<c:out value="${listValue.solution}"/>';
    bootbox.alert(msg, function() {
        console.log("Alert Callback");
    });