Pratik Jaiswal Pratik Jaiswal - 5 months ago 17
HTML Question

Print JavaScript variable in a html tag

Trying to print JS var

run_name
as a part of HTML content. Here is my small snippet out of my entire JS code:

var run_name = uiscripts.context.run.id; //uiscripts.context.run.id is a string
var markUp = "<h3 class='title' style='text-align: center'>Job is _____</h3>\r\n";
$("#startJobDialog").html(markUp);


markUp
var holds the HTML content that I want to show as a part of
#startJobDialog
. You can see the blank underlined content in markUp var. I want to fill
run_name
var into that blank. That is Job is _____. How do I do it?

So far I have tried 2 approaches:

var markUp = "<h3 class='title' style='text-align: center'>Job is <var>run_name</var></h3>\r\n";


and this:

var run_name = uiscripts.context.run.id;
var markUp = "<h3 class='title' style='text-align: center'>Job is _____</h3>\r\n";

markUp += run_name;

$("#startJobDialog").html(markUp);

Answer

Try this. You simply need to concatenate the value of variable run_name with html.

var markUp = "<h3 class='title' style='text-align: center'>Job is <var>"+run_name+"</var></h3>\r\n";