0
What I do when executing a function in javascript, it causes the previous function to start again, not accepting the changes made?
<html>
<script>
function criartabela() {
n = document.getElementById("ordem").value;
a = n * n;
for (i = 1; i <= a; i++) {
valor = '' + i;
conteudo = '<input type="number" id=' + valor + ' value="3"/>';
}
var html = "";
html += '<table border>';
for (var x = 1; x <= n; x++) {
html += '<tr>';
for (var y = 1; y <= n; y++) {
html += '<td>' + conteudo + '</td>';
}
html += '</tr>';
}
html += '</table>';
document.getElementById('diiiv').innerHTML = html;
}
function matriz() {
criartabela();
termo = [];
m = '';
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
b = document.getElementById("" + valor + "").value;
termo[i] = '\r\nA' + i + '' + j + '\r\n=' + b + '<br>';
m = m + termo[i];
}
}
document.getElementById("matriz").innerHTML = m;
}
</script>
<body>
<blockquote><blockquote> <!-- 2 tabs -->
<form>
<br><br>
Ordem da Matriz Quadrada:
<input type="number" id="ordem" value=" ">
<br><br>
</form>
<button onclick="criartabela()">Gerar Matriz a ser Preechida</button>
<br><br>
<style>ins{text-decoration:none;}</style>
<ins id="diiiv"></ins>
<br><br>
<button onclick="matriz()"> Valores dos termos </button>
<br><br>
<style>ins{text-decoration:none;}</style>
<ins id="matriz"></ins>
<br><br>
</blockquote></blockquote>
</body>
</html>
post your code so we can better understand what your real problem is.
– Gabriel Rodrigues
Join the code you have or the functionality you want for the question to be complete and we can help.
– Sergio
I’m not sure I understand, but your code is full of implicit global variables, and maybe your problem is a side effect of it. Always declare the variables with
var
.– bfavaretto