Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootbox - how to dynamically change message content?

I was wondering if there is a way to dinamically update the content of a bootbox modal.

Example

bootbox.dialog({
        message: "Hi there",
        title: "My title",
        buttons: {
            main: {
                label: "dismiss",
                className: "btn-primary",
            }
        }
    });


    newMessage = "this is a new message"

Is there a way to replace that "Hi there" with the new string newMessage?

Thanks for any help or suggestion

like image 242
Mirco Lcl Avatar asked Mar 02 '26 01:03

Mirco Lcl


2 Answers

yes, you can change bootbox msg by adding id reference to the msg. Below is sample code for it.

    bootbox.dialog({
       message: "<span id='dynamicMsg'>Hi there</span>",
       title: "My title",
       buttons: {
        main: {
            label: "dismiss",
            className: "btn-primary",
        }
      }
    });

    //Add this line wherever you want to change msg
    $("#dynamicMsg").text("This is dynamic msg");
like image 169
Akash Avatar answered Mar 03 '26 16:03

Akash


Simple! Create a generic function:

function bootBoxModal(title, message, type) {
    bootbox.dialog({
        message: message,
        title: title,
        alertType: type,
        buttons: {
            main: {
                label: 'Fechar', className: 'btn-default'}
        }
    });
}

Call the function now:

bootBoxModal("Title message", 
             "Content your message", 
             "type [alert,danger,warning,success]");
like image 22
Cesar Balzer Avatar answered Mar 03 '26 15:03

Cesar Balzer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!