<form action="call-order.php" method="post">
<div class="hold-input">
<input type="text" name="phone" placeholder="Пример: +7 123 45 67"/>
</div>
<div class="hold-btn">
<button class="btn" onclick="validate(this.form)" type="submit">Заказать звонок</button>
</div>
</form>
<script>
function showError(container, errorMessage) {
container.className = 'error';
var msgElem = document.createElement('span');
msgElem.className = "error-message";
msgElem.innerHTML = errorMessage;
container.appendChild(msgElem);
}
function resetError(container) {
container.className = '';
if (container.lastChild.className == "error-message") {
container.removeChild(container.lastChild);
}
}
function validate(form) {
var elems = form.elements;
resetError(elems.phone.parentNode);
if (!elems.phone.value) {
showError(elems.phone.parentNode, 'Укажите телефон');
}
}
</script>