-1
The idea is that I type and if the value is greater than the specified amount then it leaves the form blank, until it is all ok, however, when giving an Alert the value remains stored... What can it be?
var quantidade = 100;
$('input').keyup(()=>{
if ($('input').val() > quantidade && $('input').val().length == quantidade.length || $('input').val().length > quantidade.length)
{
$('input').val('');
}});
$('button').click(()=>{ alert($('input').val()) })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<input type="number" />
<button>Clicar</button>
You asked a question these days with that same code and I repeat, your condition on
if
is wrong, there is no property length for typenumber
!– LeAndrade