I have 3 checkbox created in a html file next to a text input. I am trying to get the input values appended to an empty array if the input box is checked. how should i do that? thank you
question = document.getElementById("question").value;
result1 = document.getElementById("result1").value;
result2 = document.getElementById("result2").value;
result3 = document.getElementById("result3").value;
correctRes1 = document.getElementById("check1");
correctRes2 = document.getElementById("check2");
correctRes3 = document.getElementById("check3");
correct = [];
function check() {
if (correctRes1.checked == true) {
correct.push(result1);
}
if (correctRes2.checked == true) {
correct.push(result1);
}
if (correctRes3.checked == true) {
correct.push(result3);
}
}
raw = JSON.stringify({
question: question,
answer: [result1, result2, result3],
correctAns: correct,
});
console.log(raw)
the code above is not working. its not appending when I am calling the function.
Aucun commentaire:
Enregistrer un commentaire