You have a quote issue. The double quotes for your string are colliding with the double quotes in your attributes in your string.
var str = "<table id="<%=tableName%>" width="70%" cellpadding="0" cellspacing="0" border="0">"
should be
var str = '<table id="<%=tableName%>" width="70%" cellpadding="0" cellspacing="0" border="0">'