Answer the question
In order to leave comments, you need to log in
Reset error when removed from input?
When you enter non-numbers, I block the send button. but when the letters are deleted and the input is empty, the button is not unlocked
<script>
var tmp = "id[<?php echo $id; ?>]";
var elem = document.getElementById(tmp);
elem.onchange = function () {
this.value = (this.value.replace(',', "."));
if (isNaN(this.value)) { // введено не число
// показать ошибку
this.className = "error";
error.innerHTML = 'Вы ввели не число. Исправьте, пожалуйста.'
document.getElementById("submit").disabled = true;
}
else
if (this.className == 'error' || this.value == "") { // сбросить состояние "ошибка", если оно есть
this.className = "";
error.innerHTML = "";
document.getElementById("submit").disabled = false;
}
};
</script>
Answer the question
In order to leave comments, you need to log in
all chiki farts. in the wrong place rules the code))))
<script>
var tmp = "id[<?php echo $id; ?>]";
var elem = document.getElementById(tmp);
elem.oninput = function () {
this.value = (this.value.replace(',', "."));
if (isNaN(this.value)) { // введено не число
// показать ошибку
this.className = "error";
error.innerHTML = 'Вы ввели не число. Исправьте, пожалуйста.'
document.getElementById("submit").disabled = true;
}
else
if (this.className == 'error' || this.value == '') { // сбросить состояние "ошибка", если оно есть
this.className = "";
error.innerHTML = "";
document.getElementById("submit").disabled = false;
}
};
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question