I need to send the value of a variable as a parameter to a javascript function when clicking on a link. The value is obtained from an AJAX response. However, I am encountering an error in the console stating that 'test' is not defined.
var test = data.fileName;
alert('Hello world ' + test); // outputs Hello world download/15__Priority____4x6__Label.JPEG
var lbDownHtml = '';
lbDownHtml += "<div><a href='" + data.functpath + "' ><span>Download Label</span></a>";
lbDownHtml += "</div>";
lbDownHtml += "<div><a id='print_Link' onclick='print_funct(test);return false;'><span>Print Label</span></a>";
lbDownHtml += "</div>";
function print_funct (test) {
alert('Hello world '+test);
}
Is there a way for me to successfully pass the 'test' variable to my function?