Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add a very dynamic inputs in the dynamic divs by jQuery
    primarykey
    data
    text
    <p>I have php code similar to this below:</p> <pre><code>foreach ($questions as $q){ foreach ($answers as $a) { echo '&lt;input type="text" id="'.$a['question_id'].'_'.$a['id_answer'].'" value="'.$a['answer'].'" /&gt;'; echo '&lt;div id="newAnswerTextBox'.$a['question_id'].'"&gt;'; } echo '&lt;button id="addNewAnswer'.$q['id_question'].'"&gt;Add new answer&lt;/button&gt;'; } </code></pre> <p>exemplary output:</p> <pre><code>&lt;input type="text" id="1_1" value="question1 answer1"&gt; &lt;input type="text" id="1_2" value="question1 answer2"&gt; &lt;input type="text" id="1_3" value="question1 answer3"&gt; &lt;div id="newAnswerTextBox1"&gt; &lt;button id="addNewAnswer1"&gt;Add new answer&lt;/button&gt; &lt;input type="text" id="2_4" value="question2 answer4"&gt; &lt;input type="text" id="2_5" value="question2 answer5"&gt; &lt;input type="text" id="2_6" value="question2 answer6"&gt; &lt;div id="newAnswerTextBox2"&gt; &lt;button id="addNewAnswer2"&gt;Add new answer&lt;/button&gt; </code></pre> <p>desired extra input after clicking first button "Add new answer":</p> <pre><code>&lt;input type="text" id="1_4" value=" "&gt; </code></pre> <p>The main question is how to add by jquery new inputbox. I can't find similar solution I'm learning yet jquery.</p> <p>I found this below but I need to add dynamic input in right div.</p> <pre><code>var num = 0; $("#addNewAnswer").click(function() { num++; $("#newAnswerTextBox").html("&lt;input type=\"text\" id=\"" + num + "\" /&gt;"); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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