Note that there are some explanatory texts on larger screens.

plurals
  1. POdiv jquery doesn't appear in javascript
    primarykey
    data
    text
    <p>I am trying to create an mcq question by using this code</p> <pre><code>&lt;div data-role="content"&gt; &lt;form name="newdocument"&gt; &lt;div id="questions" data-role="fieldcontain"&gt;&lt;input type="text" value="dsa"/&gt;&lt;/div&gt; &lt;input type="button" value="Add Question" onclick="AddQuestion();" /&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>the text box with value of dsa is working fine with the jquery using fieldcontain. but when i press the button to add question using code below</p> <pre><code>&lt;script type="text/javascript"&gt; var questionNum = 1;//question number //function to add question function AddQuestion(){ document.getElementById('questions').innerHTML+= "&lt;div id='question"+questionNum+"'&gt;"+ "&lt;div data-role='fieldcontain'&gt;"+ "Q"+questionNum+"."+ "&lt;input type='text' id='questionText"+questionNum+"' placeholder='Put your question here' data-mini='true'/&gt;"+ "&lt;input type='button' id='"+questionNum+"' name='1' value='Add Option' onclick='AddOption(this);' /&gt;"+ "&lt;div id='optionList"+questionNum+"'"+ "&lt;/br&gt;"+ "&lt;input type='radio' id='question"+questionNum+"option0' name='radio' onclick='DisableCheck(this);' /&gt;"+ "&lt;input type='text' id='question"+questionNum+"option0text' placeholder='Option 1' data-mini='true' /&gt;"+ "&lt;/br&gt;" + "&lt;/div&gt;" + "&lt;/div&gt;" + "&lt;/br&gt;"; questionNum++; } function AddOption(element){ var buttonName = element.getAttribute("name");//define unique question var buttonId = element.getAttribute("id");//define unique choice //ex: id=question1option1 for question 1 choice A if(buttonName&lt;5){ buttonName++; document.getElementById('optionList'+buttonId).innerHTML+= "&lt;input type='radio' id='question"+buttonId+"option"+buttonName+"' name='radio' onclick='DisableCheck(this);' /&gt;"+ "&lt;input type='text' id='question"+buttonId+"option"+buttonName+"text' placeholder='Option "+buttonName+"' data-mini='true'/&gt;"+ "&lt;/br&gt;"; element.name = buttonName; } else { buttonName = 1; document.getElementById('optionList'+buttonId).innerHTML= "&lt;input type='radio' id='question"+buttonId+"option"+buttonName+"' name='radio' onclick='DisableCheck(this);' /&gt;"+ "&lt;input type='text' id='question"+buttonId+"option"+buttonName+"text' placeholder='Option "+buttonName+"' data-mini='true'/&gt;"+ "&lt;/br&gt;"; element.name = buttonName; } } function DisableCheck(element){ element.checked = false; } &lt;/script&gt; </code></pre> <p>the textbox that is created by addquestion function is not the same with the textbox that is created on the form. can somebody tell me why it doesn't work?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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