Seeking assistance in converting multiple lines into a single for loop.
var optie1 = "";
if($('#form #optie1_check').is(':checked')) {
optie1 = $('#form #optie1_naam').val();
}
var optie2 = "";
if($('#form #optie2_check').is(':checked')) {
optie2 = $('#form #optie2_naam').val();
}
Struggling to find relevant information online. Need help with a for loop like this:
for (let i = 0; i < 2; i++) {
var str = "optie" + (i+1) + "_check";
var str2 = "optie" + (i+1) + "_naam";
if($('#form #' + str).is(':checked')) {
opties.push($('#form #' + str2).val());
}
}
Storing values in 'opties' array for later use, and passing it through ajax:
$.ajax({
type: "POST",
url: "voegOptiesToe.php",
data: { opties: opties },
...
});