<style>
table, td {
border: solid 1px;
text-align: center;
white-space: nowrap;
}
</style>
<input id="inp">
<div id="div"></div>
<script>
window.onload = function () {
var num = 20;
var str = '<table id="table"><tr><td>a x b, mm</td>';
for (var i = 1; i <= num; i++) {
str += '<td>' + i*50 + '</td>';
}
str += '</tr>';
for (i = 1; i <= num; i++) {
str += '<tr>';
for (var j = 0; j <= num; j++) {
if (j == 0) {
str += '<td>' + i*50 + '</td>';
} else {
str += '<td>' + i * 50 * j * 50 + '</td>';
}
}
str += '</tr>'
}
str += '</table>';
document.getElementById('div').innerHTML = str;
var table = document.getElementById('table');
var inp = document.getElementById('inp');
var tr = table.rows;
var len = tr.length;
var td, tdLen;
var value;
function calculate() {
if (isNaN(inp.value) == false && inp.value != '') {
value = parseFloat(inp.value);
} else {
value = 1;
}
for (var i = 1; i < len; i++) {
td = tr[i].cells;
tdLen = td.length;
for (var j = 1; j < tdLen; j++) {
td[j].innerHTML = i * 50 * j * 50 * value;
}
}
}
inp.onkeyup = function () {
calculate()
}
}
</script>