Hello, I created these functions that automatically create new multiple-choice questions on my page. I can create as many questions as I want, and in these answers I can have as many answers as I want. I want to write these answers and questions in the mysql database. What I have no idea how to do is how I get the id of each question and every answer. I could not think of a logic for the answers to always have an order.
Closed
<script>
var mudadiv = 0;
var novasperguntas = 0;
var mudaradio = 0;
var mudatxt = 0;
function PME() {
var html = "";
html += '<div class="main-login main-center">' +
'<div class="form-group">' + '<label for="name" class="cols-sm-2 control-label">Digite sua pergunta de multipla escolha.</label>' +
'<div class="cols-sm-10">' + '<div class="input-group">' + '<span class="input-group-addon">' +
'<i class="fa fa-user fa" aria-hidden="true">' + '</i></span>' +
'<input type="text" class="form-control" id="perguntaF' + novasperguntas + ' " placeholder="Qual a sua idade?" />' + '<br>' +
'</div>' + '</div>' + '<div class="row">' +
'<div class="col-lg-6">' + '<div class="input-group">' + '<span class="input-group-addon">' +
'<input type="radio" id="radioperFechada' + mudaradio + ' ">' + '</span>' + '<input type="text" id="textodaresposta' + mudatxt + '-' + mudadiv + ' " class="form-control" aria-label="...">' +
'</div>' + '</div>' + '<div id="maisresposta2' + mudadiv + '">' + '</div>' + '</div>' + '<div id="a'+ mudadiv + '"style="display:block">'+
'<button onclick="MaisRespostas2(' + mudadiv + ')" style="margin-top:5px" class="btn btn-info" type="button">Nova Resposta</button>' + '</div>'+
'<div id="NPME">' + '</div>' + '</div>' + '</div>' + '</div>' + '</div>' + '</div>' + '</div>' + '</div>' + '';
document.getElementById("multiplaescolha").insertAdjacentHTML('beforeend', html);
mudatxt++;
novasperguntas++;
mudadiv++;
mudaradio++;
return false;
}
var con = 0;
var myradio =0;
function MaisRespostas2(mudaduv) {
var htmlresposta = "";
htmlresposta += '<div class="col-lg-6">' + '<div class="input-group">' + '<span class="input-group-addon">' +
'<input type="radio" id="chequeRadio' + con + ' ">' + '</span>' +
'<input type="text" id="textodaresposta' + mudatxt + "-" + mudaduv + ' " " class="form-control" aria-label="...">' + '</div>' + '</div>' + '';
document.getElementById("maisresposta2" + mudaduv + "").insertAdjacentHTML('beforeend', htmlresposta);
mudatxt++;
con++;
return false;
}
</script>