javascript - Trying to replace document.write to a innerHTML but it doesn't work -
so i'm making code assignment have make loop multiplication table input variables i've gotten table work want input a<div id='buffer'></div>
, not using 'document.write'
.
var _buffer = document.getelementbyid('buffer'); var rows=prompt("enter rows"); var columns=prompt('enter columns'); document.write("<table border='1'>"); (var a=1; < rows ; a++) { document.write("<tr>"); for(var b=1; b< columns; b++) { document.write("<td>"+a*b+"</td>"); } document.write("</tr>"); } document.write("</table>");
i want use _buffer.innerhtml
instead of document.write
when change out the code doesn't print information in table looking , suggestions thanks!
you can initialize variable (t
in example below), , put text string, assign innerhtml
:
var _buffer = document.getelementbyid('buffer'); var rows=prompt("enter rows"); var columns=prompt('enter columns'); var t = "<table border='1'>"; (var a=1; < rows ; a++) { t = t + "<tr>"; for(var b=1; b< columns; b++) { t = t + "<td>"+a*b+"</td>"; } t = t + "</tr>"; } t = t + "</table>"; _buffer.innerhtml = t;
Comments
Post a Comment