I am trying to create an mcq question by using this code
<div data-role="content">
<form name="newdocument">
<div id="questions" data-role="fieldcontain"><input type="text" value="dsa"/></div>
<input type="button" value="Add Question" onclick="AddQuestion();" />
</form>
</div>
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
<script type="text/javascript">
var questionNum = 1;//question number
//function to add question
function AddQuestion(){
document.getElementById('questions').innerHTML+=
"<div id='question"+questionNum+"'>"+
"<div data-role='fieldcontain'>"+
"Q"+questionNum+"."+
"<input type='text' id='questionText"+questionNum+"' placeholder='Put your question here' data-mini='true'/>"+
"<input type='button' id='"+questionNum+"' name='1' value='Add Option' onclick='AddOption(this);' />"+
"<div id='optionList"+questionNum+"'"+
"</br>"+
"<input type='radio' id='question"+questionNum+"option0' name='radio' onclick='DisableCheck(this);' />"+
"<input type='text' id='question"+questionNum+"option0text' placeholder='Option 1' data-mini='true' />"+
"</br>" +
"</div>" +
"</div>" +
"</br>";
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<5){
buttonName++;
document.getElementById('optionList'+buttonId).innerHTML+=
"<input type='radio' id='question"+buttonId+"option"+buttonName+"' name='radio' onclick='DisableCheck(this);' />"+
"<input type='text' id='question"+buttonId+"option"+buttonName+"text' placeholder='Option "+buttonName+"' data-mini='true'/>"+
"</br>";
element.name = buttonName;
} else {
buttonName = 1;
document.getElementById('optionList'+buttonId).innerHTML=
"<input type='radio' id='question"+buttonId+"option"+buttonName+"' name='radio' onclick='DisableCheck(this);' />"+
"<input type='text' id='question"+buttonId+"option"+buttonName+"text' placeholder='Option "+buttonName+"' data-mini='true'/>"+
"</br>";
element.name = buttonName;
}
}
function DisableCheck(element){
element.checked = false;
}
</script>
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?