I want to display a list of data stored in array and against each data I want to put a yes and no radio button. I have generated radio button dynamically, but from all the radio buttons I can only select one at a time, but it should be like, for each data I can select either yes or no. Please help as I am new to JavaScript.
function displayData()
{
var data=['Apple', 'Banana', 'Kiwi'];
var output="";
var output2="";
var dataList;
for(var i=0; i< data.length; i++)
{
dataList=data[i];
output+= '<input type="checkbox" value='+dataList+' name="box2">' + ' ' + dataList+' '+'<br><br>';
output2+= 'yes:<input type="radio" value="yes" name="box2">'+'no:<input type="radio" value="yes" name="box2">'+'<br><br>';
document.getElementById("dataList").innerHTML=output;
document.getElementById("radioBtn").innerHTML=output2;
}
}
<html>
<body onload="displayData()">
<div class="row">
<div class="col-sm-4"><div id="dataList"> </div></div>
<div class="col-sm-4"><div id="radioBtn"></div></div>
</div>
</body>
</html>
innerHTMLin instead of after the loop?