2
I am making a very simple game in html and javascript, the idea is that the user put the result of each operation, and if it is right, appear an Alert for it. I wanted to use table because I want to exercise this question. The program is almost ready, but I can’t get the user to give a "Ubmit" so I can check if it’s right. I even tried to use a Ubmit there, but I ended up doing a trick that did not work. I googled and found nothing related. From now on... J.G..
function olosko() {
var x = document.getElementById("tabela").rows[0].cells[4];
var y = document.getElementById("tabela").rows[1].cells[4];
var z = document.getElementById("tabela").rows[2].cells[4];
var r = document.getElementById("tabela").rows[3].cells[4];
x.innerHTML = "<input type='text'>";
y.innerHTML = "<input type='text'>";
z.innerHTML = "<input type='text'>";
r.innerHTML = "<input type='text'>";
var a = document.getElementById("tabela").rows[0].cells[0];
var b = document.getElementById("tabela").rows[0].cells[2];
var c = document.getElementById("tabela").rows[1].cells[0];
var d = document.getElementById("tabela").rows[1].cells[2];
var e = document.getElementById("tabela").rows[2].cells[0];
var f = document.getElementById("tabela").rows[2].cells[2];
var g = document.getElementById("tabela").rows[3].cells[0];
var h = document.getElementById("tabela").rows[3].cells[2];
a.innerHTML = parseInt(Math.random()*10);
b.innerHTML = parseInt(Math.random()*10);
c.innerHTML = parseInt(Math.random()*10);
d.innerHTML = parseInt(Math.random()*10);
e.innerHTML = parseInt(Math.random()*10);
f.innerHTML = parseInt(Math.random()*10);
g.innerHTML = parseInt(Math.random()*10);
h.innerHTML = parseInt(Math.random()*10);
if(a+b==x && c-d==y && e/f==z && g*h==r){
alert("VC GANHOU!");
}
}
<button onclick="olosko()">ESTOU PRONTO!</button>
<table id="tabela" border=1 width=400 height=400>
<tr>
<td></td>
<td>+</td>
<td></td>
<td>=</td>
<td></td>
</tr>
<tr>
<td></td>
<td>-</td>
<td></td>
<td>=</td>
<td></td>
</tr>
<tr>
<td></td>
<td>รท</td>
<td></td>
<td>=</td>
<td></td>
</tr>
<tr>
<td></td>
<td>X</td>
<td></td>
<td>=</td>
<td><div id="olosko()"></div></td>
</tr>
</table>
<submit><button>ACABEI!</button></submit>
I don’t think it’s clear what this Ubmit is going to do, is it going to be a button ? or a message with a Ubmit ? when it will occur, after filling all fields ?
– Thiago Friedman
Well, this button will be for the user to click after filling the table. He will click this to check if the answers are correct, if they are, an 'Alert' saying this, otherwise an Alert will also show up saying it is wrong.
– J. Gaidzinski
to submit data you need a form. The HTML you posted has no form.
– MFedatto