So at the time I try to validate a fieldset of radio buttons where the user have to check their sex. Because I’m new to js and I don’t find anything useful when I google I ask here.
So this is my code: HTML
<body>
<div id="popupKontakt" class="clearfix,">
<section id="kontakt">
<div class="intro-container">
<h1>Kontakt</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Saepe commodi, quod, quisquam cum ea itaque dolore eum sunt ipsam deleniti rerum qui nemo inventore ab? Commodi, voluptates. Aspernatur, neque nesciunt.</p>
</div>
<form id="kontakt-form" name="Kontakt-form" onsubmit="return validation()" >
<div class="Container">
<div class="row">
<fieldset name="geschlecht">
<legend>Wählen Sie Ihr Geschlecht:</legend>
<div>
<input type="radio" id="Maennlich" name="Maennlich" value="Maennlich" />
<label for="Maennlich">Männlich</label>
</div>
<div>
<input type="radio" id="Weiblich" name="Weiblich" value="Weiblich" />
<label for="Weiblich">Weiblich</label>
</div>
<div>
<input type="radio" id="Divers" name="Divers" value="Divers" />
<label for="Divers">Divers</label>
</div>
</fieldset>
and here the js:
function validation() {
let geschlecht = document.forms["Kontakt-form"]["geschlecht"].value;
console.log(geschlecht);
if (Maennlich === null) {
if (Weiblich === null) {
if (Divers === null) {
alert("Bitte geben Sie ihren Namen an");
}
}
}