0
I have a browser game ready. It’s a game that only puts the answer in one form, if it’s right, gets points, changes an image, blocks the text box and a few other 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. Hence the system will already create these 60 Forms automatic when possible load on the page.
I was trying to implement how 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 this way and it wasn’t. Text boxes work. But no JS function works. How: onkeypress='validar('0')' nem onclick='verificaChecks('11')'
I did a test putting the form already on body
and only adding by innerHTML
the rest of the code. Hence the function of form works, but the Checklist not yet, probably still being inserted by innerHTML
. I only did this for testing because I need the form to be created in innerHTML
.
The impression is that when some content is added, being form’s or checklists with functions in the div
for innerHTML
functions cannot find path to file .js
as out of scope.
This javascript will need a good cleaning... Put your whole page and what you have on
arquivo.js
that we help fix it...– Sergio
Index: http://pastebin.com/N52MScSb // Archive js: http://pastebin.com/D4EEcHtv
– Carlos Moura
I guess I’ll have to improve the structure then.. To be possible only one form..?
– Carlos Moura