Here is my code:
<!DOCTYPE html>
<head>
<title>Tests</title>
<meta http-equiv='Content-Type' content='text/html; charset=utf8'>
<script type="text/javascript">
function closeSign(){
document.getElementById('window_fler').style.display = 'none';
document.getElementById('wrap_fler').style.display = 'none';
}
function validate_fler(){
if (document.forms["fler_form"]["signDate"].value.length == 0) { return false };
if (document.forms["fler_form"]["signTime"].value.length == 0) { return false };
if (document.forms["fler_form"]["signFIO"].value.length == 0) { return false };
if (document.forms["fler_form"]["signPhone"].value.length == 0) { return false };
document.getElementById('window_fler').style.display = 'block';
document.getElementById('wrap_fler').style.display = 'block';
}
</script>
<style type="text/css">
#wrap_fler{
display: none;
opacity: 0.8;
position: fixed;
background-color: rgba(1, 1, 1, 0.725);
z-index: 100;
overflow: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
padding: 16px;
}
#window_fler{
height: 400px;
width: 400px;
display: none;
z-index: 200;
position: fixed;
margin: 150px auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
padding: 30px;
background: #fff;
}
</style>
</head>
<body>
<form role="form" name="fler_form" action="" data-email-subject="Contact Form" data-show-errors="true">
<div>
<label for="dayTime1">Выберите дату:</label>
<input name="signDate" type="text" placeholder="Пожалуйста, выберите дату" id="dayTime1" required>
</div>
<div>
<label for="hourTime">Выберите время:</label>
<select name="signTime" id="hourTime">
<option> </option>
<option value="10">10:00</option>
<option value="11">11:00</option>
<option value="12">12:00</option>
<option value="13">13:00</option>
<option value="14">14:00</option>
<option value="15">15:00</option>
<option value="16">16:00</option>
<option value="17">17:00</option>
<option value="18">18:00</option>
<option value="17">19:00</option>
<option value="18">20:00</option>
</select>
</div>
<div>
<label for="fio">Ваше имя и фамилия:</label>
<input name="signFIO" type="text" placeholder="Пожалуйста, введите Ваше имя и фамилию" id="fio" required>
</div>
<div>
<label for="phone">Номер телефона:</label>
<input name="signPhone" type="text" placeholder="Пожалуйста, введите Ваш номер телефона" id="phone" required>
</div>
<div>
<button type="submit" onclick="return validate_fler()">
<span>Записаться</span></button>
</div>
</form>
<div id="wrap_fler" onclick="closeSign()"></div>
<div id="window_fler">
<h3>
Ваша заявка принята. <br/>
В ближайшее время с вами свяжется администратор нашего салона, что бы подтвердить запись.
</h3>
<a href="#" onclick="closeSign()" style="margin: 30px 0 0 0;">ЗАКРЫТЬ</a>
</div>
</body>
</html>
I need to validate form for presence of all fields. Next I need to show to user the message in div window_fler. User can click the button to close the div. In my case when i click on button in the form I see message div is shown and quickly closed. Whats wrong in my code?
return falseafter each check, so the code won't reach the part where the div is shown.