I'm trying to get an error message when select is set to default and nothing is selected. For input fields the code works, but I can't figure out where I'm wrong for the select part. Anyone help me?
Fiddle: https://jsfiddle.net/snake93/1sLtk2a7/2/
//Error Msg for input field
function validateForm() {
let x = document.forms["myForm"]["fname"].value;
if (x == "") {
alert("Name must be filled out");
return false;
}
}
<input type="text" name="fname" form="myForm">
<select id="select-sex" form="myForm" name="radios">
<option id="opt-default" form="myForm" selected>Select...</option>
<option id="sexuomo" name="radios" value="Male" form="myForm">Uomo</option>
<option id="sexdonna" name="radios" value="Female" form="myForm">Donna</option>
</select>
<button onclick="validateForm()">Submit</button>
<form name="myForm" id="myForm" onsubmit="return validateForm()" method="post">
</form>