I have a browser game ready. It is a game that only puts the answer in a form, if it is right, earn points, change an image, block the text box and a few more things. In a v2 of this system, my idea was an automatic generator of these questions, for example, I have in another file several questions and answers, I know, 60. Then the system will already create these 60 forms automatic when der load on the page.
I was trying to implement as innerHTML
:
function mais(campo) {
var i;
var k;
for (i=0;i<campo;i++) {
Linha1 = "<form method='POST' onkeyup='validar('0')' onkeypress='validar('0')' name='anime0'>";
Linha2 = "<div align='center'><img id='imagem0' src='fundo.png'/></div>";
Linha3 = "<audio controls preload='auto' id='playTune'><source src='music/001.mp3'></audio>";
Linha4 = "<div align='center'><br />Nome do Anime<br />";
Linha5 = "<input name='caixa0' type='text' id='caixa0' size='30' maxlength='30'/><br /><br /></div></form>";
Linha6 = "<input type='checkbox' name='itemName11' onclick='verificaChecks('11')' id='item34'/>Dica 1: (-1Pts)<input type='text' id='txt34' size='40' maxlength='40' disabled/>";
document.getElementById("Linha1").innerHTML+=Linha1+Linha2+Linha3+Linha4+Linha5+Linha6;
/Lá em baixo, no body:
<div id="Linha" align="center">
</div>
I tested it that way and it was not. The text box works. But no function in JS works. As onkeypress='validar('0')' nem onclick='verificaChecks('11')'
I made a test by putting the form already in the body
and only adding% with% of the rest of the code. Hence the form function works, but the checklist does not yet, probably because it is still being inserted by innerHTML
. I just did this for testing because I need the form to be created in innerHTML
.
The impression given is that when some content is added, form's or checklists with functions in innerHTML
by div
functions do not find path to file innerHTML
as out of scope.