INTRO: I am kinda new to JavaScript and need a little help. What I am trying to do is build is return a string of html, and I need to introduce some variables into a html table.
PROBLEM: I am trying to do forEach loop to collect data I would like to output. I can loop through and get the data to return just fine, however I have my forEach loop inside another function.
Code:
'<table>' +
'<tr><th>Product Details:</th><th></th><th></th><th></th></tr>' +
'<tr><th>Product</th><th>Manufacture Site</th><th>Business</th><th>Hazmat #</th><th>MSDS</th></tr>' +
myFunction() +
'</table>'...
Sorry that it's a little hard to read.
Function:
function myFunction() {
productDetailsGrid.items.forEach(function(item) {
var prod = item.data.Product;
var sites= item.data.Sites;
var mSDSID = item.data.MSDSID;
var msdsLink = item.data.MSDSLink;
var bus = item.data.Business;
var hazMatNumber = item.data.HazMatNumber
var str = '<tr><th>' + prod + '</th><th>' + sites+ '</th><th>' + bus + '</th><th>' + hazMatNumber + '</th><th><a href="' + msdsLink + '">' + mSDSID + '</a></th></tr>';
return str;
});
}
So, since I receive the data, how can I return each str as a string to the string that calls it?