document.getElementById("main-form").addEventListener("submit", CheckForm);
function CheckForm(event) {
event.preventDefault();
var el = document.getElementById("main-form");
var name = el.name.value;
var pass = el.pass.value;
var repas = el.repas.value;
var state = el.state.value;
if (name == "" || pass == "" || repas == "" || state == "") {
fail = "Заполните все поля"
}
else if (pass != repas){
fail = "Пароли не совподают"
}
if (fail != "") {
document.getElementById("error").innerHTML = fail;
return false;
}
else{
alert("Все данные введены првильно");
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form id="main-form" method="post">
<label for="name">Введите имя: </label>
<input type="text" name="name" id="name" placeholder="Имя"> <br><br>
<label for="password">Введите пароль: </label>
<input type="password" name="pass" id="pass" placeholder="Пароль"> <br><br>
<label for="repas">Подтвердите пароль: </label>
<input type="password" name="repas" id="repas" placeholder="Пароль"> <br><br>
<label for="man" >М: </label>
<input type="radio" name="state" id="man" >
<label for="woman">Ж: </label>
<input type="radio" name="state" id="woman" > <br><br>
<div id="error" style="color: red;"></div>
<input type="submit" name="submit" value="Готово">
<input type="reset" value="Сбросить">
</form>
<script src="/js/main.js"></script>
</body>
</html>