Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should actually create an input element in javascript and append it to your container through <code>appendChild</code> instead of using <code>innerHTML +=</code>.</p> <p>You should also set an ID for those fields, not just a name. But it can be the same as theirs names.</p> <p>Like this</p> <pre><code>var input = document.createElement("input"); input.type = "text"; input.name = input.id = qboxName; document.getElementById("response").appendChild(input); </code></pre> <p>And then, you know, do the same for the other input field you need. I know you need a text label for the boxes, or whatever, just do the same process to insert a span tag before them.</p> <p>Also, I don't see a reason for those two counting variables. Instead of <code>qcountBox</code> and <code>acountBox</code> it's totally possible to have only one single counting variable. Maybe I'm wrong but shouldn't you increase this counting before setting the boxes names?</p> <p>As for removing it, you can use the <code>removeChild</code> method, then, decrease your counting variable. like this:</p> <pre><code>function removeInput() { var qboxName = "question" + count; var aboxName = "answer" + count; document.getElementById("response").removeChild(document.getElementById(aboxName)); document.getElementById("response").removeChild(document.getElementById(aboxName)); count--; } </code></pre> <p>Maybe if you're going to insert other elements together with these fields, like span tags for labels etc, it would be better to wrap them all up in a div or something, then simply do a <code>removeChild</code> to this container div only.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload