s.k.Soni s.k.Soni -4 years ago 72
HTML Question

How to store from external javascript variable value to html variable value

I want to store the jquery variable value to the html variable value.

Here is my code,

This is the javascript function which is in external javascript page

function createImage(settings) {
var kk = createCanvas(settings)[0].toDataURL('image/png');
}


Now, this is in html page

var karan = kk;
<img id="containerQrCode" src = "+ karan +" alt="qr image" />


Now, how can I move the kk value which is in external javascript page to the karan variable which is in html page.

Thanks In Advance.

Answer Source

I will suggest you work with the DOM. Some thing like the below if your are jQuery.

function createImage(settings) {
    var kk = createCanvas(settings)[0].toDataURL('image/png');
    $("#containerQrCode").attr("src", kk);
}

below can be tried if not using jquery

function createImage(settings) {
    var kk = createCanvas(settings)[0].toDataURL('image/png');
    document.getElementById("containerQrCode").setAttribute("src", kk);
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download