If you want to restrict the value to be entered to say R$ 100,00 (or any other value), you must compare the content of the input with 100 (or the desired value) and display the alert. In the case below, I’ve pasted a spanwith the id alerta which is filled in with the Valor inválido.
If the value is greater than 100, the content of span is removed.
const ValorImovel = document.querySelectorAll("#ValorImovel")
function MontaAlerta(event) {
// var numb = "100";
if (event.target.value <= 100) { //o valor atual é menor ou igual a 100?
document.getElementById('alerta').innerHTML = 'Valor inválido'; //mostro o alerta
console.log(event.target.value)
} else { //valor acima de 100
console.log('error')
document.getElementById('alerta').innerHTML = ''; //limpo o alerta
}
}
window.addEventListener("keyup", MontaAlerta)
<form>
<div class="centered-form">
<div class="preco-item">
<div>
<input id="ValorImovel" name="ValorImovel" class="form-control input-form" placeholder="R$ 0" type="text" />
</div>
<span id="alerta"></span>
</div>
</div>
</form>
Remember that in this case, the only processing is to warn that the value is invalid, but still, any value is being accepted, so further processing must be done.
I also suggest you use a input of the kind number with the attribute min="100" which will instruct the browser to restrict the range of values accepted in the example:
<form>
<div class="centered-form">
<div class="preco-item">
<div>
<input id="ValorImovel" name="ValorImovel" class="form-control input-form" placeholder="R$ 0" type="number" min="100"/>
</div>
<button type="submit">Enviar</button>
</div>
</div>
</form>
In the above case, the browser itself will take care to refuse lower values than 100, the downside is that the feedback will only exist at the time of submission, but you can match the event of keyup.
PERFECT, it worked and I could understand very well, thank you very much! : D
– SkywalkerJr
Please, we are here to help. Remember to always accept the answers. See you later.
– Marcos Alexandre
Just a detail. , this input should be like number to avoid passing something that is not number.
– Cmte Cardeal
understood, thank you again!
– SkywalkerJr