how to show variables in sweetalert2

Mia picture Mia · May 19, 2017 · Viewed 7.1k times · Source

I am trying to use sweetalert2 which seems to be good as easy to implement modals but it seems to be limited or I am just being thick. All I am trying to do is when it is activated I want it to show a javascript variable but it seems I cannot do this without JSON and loading all sorts? Is it me or am I being thick?

The var I want to show is this

            var ad1 = test5+' '+place.formatted_address;

and the way I am trying to show it is :

swal("details", "details 2"+ad1)  

})

Doing my head in, I have never used modals before either by the way but thanks for any help

Answer

Mohit Bhardwaj picture Mohit Bhardwaj · May 19, 2017

I added a variable here and it works just fine. Can you check if this is what you want:

var testVar = "TestVariable";

swal({
  title: "Error!",
  text: "Here's my " + testVar,
  type: "error",
  confirmButtonText: "Cool" 
 });
<script src="http://t4t5.github.io/sweetalert/dist/sweetalert-dev.js"></script> <link rel="stylesheet" type="text/css" href="http://t4t5.github.io/sweetalert/dist/sweetalert.css">