javascript - I'm having trouble getting my JS variable display within my HTML -


<td id = "customername" style="font:12px arial,helvetica,sans-serif;color:#000001;padding:3px 0px 3px 10px">dear&nbsp;<script>document.getelementbyid("customername").innerhtml = custname</script>,</td>    </tr>    <tr>

i'm creating email template company work for. can't seem js variable custname display within html snippet id'd customername table i've posted above.

edit:

here full html code, variable within javascript program using suitescript api

/**   * @napiversion 2.x   * @nscripttype usereventscript   * @nmodulescope sameaccount   */  define(['n/email', 'n/record', 'n/search'],function(email, record, search) {      function beforeload(scriptcontext) {      	      }      function beforesubmit(scriptcontext) {        }      function aftersubmit(scriptcontext) {      	var fromid = 450103; // internal id      	var recordtosend = record.load({ //fake customer      		type: record.type.customer,      		id : 450104,       		isdynamic: false      	});       	      	var salesorder = record.load({      		type: record.type.sales_order,      		id : 536583,      		isdynamic: false      	});       	      	var department = salesorder.getvalue({      		fieldid : 'department'      	});      	      	var departmentnames = ['fire pits direct', 'fireplace remote controls', 'skytech fireplace remotes', 'spotix', 'kick ass grills', 'teak furniture classics'];       	var deptname = "";       	      	for(var = 19; < 25; i++){      		if(i == department){      			deptname = departmentnames[i-19];       		}      	}      	      	var subjectforemail = "your order has shipped "+ deptname + "!";       	var custname = "this customer";      	      	var emailbody = '<center></center>\      		<table style="border:1px black solid;">\      		<tbody><tr><td><img src="http://www.spotix.com/images/email/spotix-family-stores_horizontal.jpg" alt="spotix family of stores" align="middle"></td>	</tr><tr><td bgcolor="#ff880f"><span style="padding-bottom:10px;font-weight: bold;font-family: arial,helvetica,sans-serif;font-size:28px;line-height: 34px;">&nbsp;&nbsp;&nbsp;great news! order on way...</span></td>\      		</tr>    <tr>    	<td id = "customername" style="font:12px arial,helvetica,sans-serif;color:#000001;padding:3px 0px 3px 10px">dear&nbsp;,</td>    </tr>    <tr>\      		<td style="font:12px arial,helvetica,sans-serif;color:#000001;padding:3px 0px 3px 10px">we\'ve shipped {createdfrom}</td>    </tr>    <tr>			  <td align="center" bgcolor="#ff880f" style="font-family:verdana,arial,sans-serif;font-size:16px;color:#000000;font-weight: bold;text-align:left;text-decoration:none!important;padding-top:10px;padding-bottom:10px;padding-left:15px;padding-right:15px">shipping method - {shipmethod}</td>\      		</tr>    <tr>    	<td width="444" align="left" valign="top" style="font:12px arial,helvetica,sans-serif;color:#000001;padding:3px 0px 3px 10px" bgcolor="#eee9e7"><b>ship to</b></td>    </tr>        <tr>    	<td style="font-family:verdana,arial,sans-serif;font-\      		size:12px;color:#000000;text-decoration:none!important;padding-top:10px;padding-bottom:10px;padding-left:15px;padding-right:15px">{shipaddress}<br></td></tr><tr><td width="444" align="left" valign="top" style="font:12px arial,helvetica,sans-serif;color:#000001;padding:3px 0px \      		3px 10px" bgcolor="#eee9e7"><b>tracking info</b></td></tr><tr><td style="font-family:verdana,arial,sans-serif;font-size:12px;color:#000000;text-decoration:none!important;padding-top:10px;padding-bottom:10px;padding-left:15px;padding-right:15px">{shipmethod} \      		{trackingnumbers}</td></tr><tr><td width="444" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody><tr><td width="444" align="left" valign="top"><table border="0" cellpadding="0" cellspacing="0" height="21" width="100%"><tbody><tr><td \      		align="left" bgcolor="#eee9e7" style="font:12px arial,helvetica,sans-serif;color:#000001;padding:3px 0px 3px 10px" valign="bottom"><b>details</b></td> </tr><tr><td align="left" valign="top" width="262"><span style="font-size: 11px;">qty:&nbsp;{quantity}</span><span \      		style="font-size: 11px;">&nbsp;sku:</span>{custcol_item_sku}<span class="apple-tab-span" style="font-size: 11px; white-space: pre;"></span><span style="font-size: 11px;">&nbsp;item:</span>{item.description}</td></tr></tbody></table></td></tr></tbody></table></td></tr>\      		</tbody></table>thanks order!questions? call now: mon-fri 8-5 cst 888.977.6849<img src="http://www.spotix.com/images/email/benefits-member_tp.jpg" alt="spotix benefits" align="middle">\      		<script>document.getelementbyid("customername").innerhtml = custname</script>';       		      	      	email.send({      		author: fromid,      		recipients: fromid,      		subject: subjectforemail,      		body: emailbody,      		isinternalonly: false      		      	});       	  }        return {          beforeload: beforeload,          beforesubmit: beforesubmit,          aftersubmit: aftersubmit      };        });
var emailbody = '<center></center>\      		<table style="border:1px black solid;">\      		<tbody><tr><td><img src="http://www.spotix.com/images/email/spotix-family-stores_horizontal.jpg" alt="spotix family of stores" align="middle"></td>	</tr><tr><td bgcolor="#ff880f"><span style="padding-bottom:10px;font-weight: bold;font-family: arial,helvetica,sans-serif;font-size:28px;line-height: 34px;">&nbsp;&nbsp;&nbsp;great news! order on way...</span></td>\      		</tr>    <tr>    	<td id = "customername" style="font:12px arial,helvetica,sans-serif;color:#000001;padding:3px 0px 3px 10px">dear&nbsp;,</td>    </tr>    <tr>\      		<td style="font:12px arial,helvetica,sans-serif;color:#000001;padding:3px 0px 3px 10px">we\'ve shipped {createdfrom}</td>    </tr>    <tr>			  <td align="center" bgcolor="#ff880f" style="font-family:verdana,arial,sans-serif;font-size:16px;color:#000000;font-weight: bold;text-align:left;text-decoration:none!important;padding-top:10px;padding-bottom:10px;padding-left:15px;padding-right:15px">shipping method - {shipmethod}</td>\      		</tr>    <tr>    	<td width="444" align="left" valign="top" style="font:12px arial,helvetica,sans-serif;color:#000001;padding:3px 0px 3px 10px" bgcolor="#eee9e7"><b>ship to</b></td>    </tr>        <tr>    	<td style="font-family:verdana,arial,sans-serif;font-\      		size:12px;color:#000000;text-decoration:none!important;padding-top:10px;padding-bottom:10px;padding-left:15px;padding-right:15px">{shipaddress}<br></td></tr><tr><td width="444" align="left" valign="top" style="font:12px arial,helvetica,sans-serif;color:#000001;padding:3px 0px \      		3px 10px" bgcolor="#eee9e7"><b>tracking info</b></td></tr><tr><td style="font-family:verdana,arial,sans-serif;font-size:12px;color:#000000;text-decoration:none!important;padding-top:10px;padding-bottom:10px;padding-left:15px;padding-right:15px">{shipmethod} \      		{trackingnumbers}</td></tr><tr><td width="444" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody><tr><td width="444" align="left" valign="top"><table border="0" cellpadding="0" cellspacing="0" height="21" width="100%"><tbody><tr><td \      		align="left" bgcolor="#eee9e7" style="font:12px arial,helvetica,sans-serif;color:#000001;padding:3px 0px 3px 10px" valign="bottom"><b>details</b></td> </tr><tr><td align="left" valign="top" width="262"><span style="font-size: 11px;">qty:&nbsp;{quantity}</span><span \      		style="font-size: 11px;">&nbsp;sku:</span>{custcol_item_sku}<span class="apple-tab-span" style="font-size: 11px; white-space: pre;"></span><span style="font-size: 11px;">&nbsp;item:</span>{item.description}</td></tr></tbody></table></td></tr></tbody></table></td></tr>\      		</tbody></table>thanks order!questions? call now: mon-fri 8-5 cst 888.977.6849<img src="http://www.spotix.com/images/email/benefits-member_tp.jpg" alt="spotix benefits" align="middle">\      		<script>document.getelementbyid("customername").innerhtml = custname</script>';

when write custname without "" or '', javascript thinks referring variable. looks variable name custname doesn't find throws referenceerror.

make sure custname defined variable , string. or, use normal string.

var custname = 'john'; document.getelementbyid("customername").innerhtml = custname; 

or use string.

document.getelementbyid("customername").innerhtml = 'john'; 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -