We have to make a website as a project. We have a form with text inputs, dropdown and checkboxes. I already have the code for checking if there's at least one checkbox selected. But when the other fields aren't filled the script still continues. I want to check first if the other fields are filled before it checks the checkboxes. And then continue to the next page. I couldn't find any help so im begging you guys to help me.
Code:
<!-- Angabenfelder -->
<div class="w3-container" style="font-family:Arial">
<br>
<div class="w3-card-4">
<div class="w3-container" style="background-color: maroon">
<h1 style="color: white; text-align: center">Bitte geben Sie folgende Daten ein:</h1>
</div>
<form method="post" name="eintragen_schueler" class="w3-container">
<div style="color: maroon">
<p>
<b>Vorname</b>
<input class="w3-input w3-border w3-round" type="text" id="vorname" name="vorname" required>
<p>
<b>Nachname</b>
<input class="w3-input w3-border w3-round" type="text" id="nachname" name="nachname" required>
<p>
<b>Geburtsdatum</b>
<input class="w3-input w3-border w3-round" type="date" id="geburtsdatum" name="geburtsdatum" required>
<p>
<b>E-Mail</b>
<input class="w3-input w3-border w3-round" type="email" id="email" name="email" required>
<p>
<b>Schulstufe</b>
<select class="w3-select w3-border w3-round" id="schulstufe" name="schulstufe" required>
<option value="" disabled selected>Schulstufe auswählen</option>
<option value="1">Mittelschule</option>
<option value="2">Oberschule</option>
</select>
</p>
<br>
<b><div style="font-size: 20px">In welchen Fach benötigen Sie Hilfe?</div></b>
</div>
<p>
<input class="w3-check" id="mat" type="checkbox" name="fach" value="mat"> <label>Mathematik</label>
<p>
<input class="w3-check" type="checkbox" name="fach" value="deu"> <label>Deutsch</label>
<p>
<input class="w3-check" type="checkbox" name="fach" value="eng"> <label>Englisch</label>
<p>
<input class="w3-check" type="checkbox" name="fach" value="ita"> <label>Italienisch</label>
<p>
<input class="w3-check" type="checkbox" name="fach" value="che"> <label>Chemie</label>
<p>
<input class="w3-check" type="checkbox" name="fach" value="phy"> <label>Physik</label>
<p>
<input class="w3-check" type="checkbox" name="fach" value="inf"> <label>Informatik / IKT</label>
<br>
<div class="w3-container w3-center">
<p>
<button class="w3-button w3-mobile w3-highway-red w3-border" name="btn_senden" onclick="check()">Senden</button>
<button type="button" class="w3-button w3-mobile w3-highway-red w3-border" onclick="history.go(-1)">Zurück</button>
</div>
</form>
</div>
</div>
<br>
<script>
function check()
{
var checkboxes = document.getElementsByName("fach");
var okay = false;
for(var i = 0, l = checkboxes.length; i < l; i++)
{
if(checkboxes[i].checked)
{
okay = true;
break;
}
}
if (okay)
{
window.location.assign("eintragung_erfolgreich.html")
}
else alert("Bitte wählen Sie mindestens ein Fach.");
}
</script>
I can't find anything online that helps me.