If you’re going to do this dynamically, use Javascript with the event blur
, equalling the value if lower.
The min
can be used for validation purposes if you are using a form to be submitted.
If this is not the case, you can use the event blur
down below:
document.querySelector("[name=valor-em-dinheiro]").onblur = function(){
// valor do primeiro input. Se for vazio vira 0
var total = document.querySelector("[name=total]").value || 0;
// valor do segundo input
var dindin = this.value;
// se o segundo for menor que o primeiro, iguala
if(Number(dindin) < total) this.value = total;
}
<input type="number" name="total" value="25" required>
<br>
Digite um valor menor e tecle TAB:
<input type="number" name="valor-em-dinheiro" class="form-control text-right" required>
If you submit the form, you can change the min
dynamically:
document.querySelector("[name=total]").oninput = function(){
// altera o min do segundo input de acordo com o valor digitado
document.querySelector("[name=valor-em-dinheiro]").min = this.value;
}
document.querySelector("[name=valor-em-dinheiro]").oninput = function(){
// seleciona o primeiro input
var total = document.querySelector("[name=total]");
// altera o min de acordo com o valor de total
this.min = total.value;
}
<form>
<input type="number" name="total" value="25" required>
<input type="number" name="valor-em-dinheiro" class="form-control text-right" required>
<br>
<button>Enviar</button>
</form>
But the value of the first and dynamic
– Vision Development
You can change the minimum value with JS too, doing
document.getElementById("elemento").min = "25";
, for example.– João Pedro Henrique