Many mistakes indeed :)
1) you are trying to access the second form using the wrong id
<form id= <%= "selection_examen"+i %> >...
...
document.getElementById("#question_selection"+i).appendChild(inputoui);
2) you need to concat the input's id using straight js, no EJS is needed.
To fix it do this:
input.id= "selection_non"+i;
Instead of:
input.id= <%= "selection_non"+i %>;
3) you are creating an element without declaring and assigning it to a variable, and the element you were creating wasn't a valid input
To fix it do this:
var inputnon = document.createElement("input");
inputnon.type ="radio";
...
Instead of this:
document.createElement("inputnon");
input.type ="radio";
...
- you do not need innerHTML in a radio button so you can safely remove the following lines:
input.innerHTML="Non"; ... input.innerHTML="Oui";
Try the following code (did not run it though, so it might have more errors):
<script>
function exam(i) {
alert(i); // just to check it is correctly triggered (it is the case)
// hopefully the following code will run:
var inputnon = document.createElement("input");
inputnon.type ="radio";
inputnon.id= "selection_non"+i;
inputnon.name="selection";
inputnon.value="non";
document.getElementById("question_selection"+i).appendChild(inputnon);
var inputoui = document.createElement("input");
inputoui.type ="radio";
inputoui.id= "selection_oui"+i;
inputoui.name="selection";
inputoui.value="oui";
document.getElementById("question_selection"+i).appendChild(inputoui);
}
</script>