I need to do a two-field check of a form before submitting it.
I need to check if the field 'minimum_store' is less than the 'maximum_store' field. I have already made countless attempts and none worked well, incredible as it seems sometimes works and sometimes not (sometimes the conditions are simply ignored).
Here's my code:
In the FORM form tag with BUTTON is like this (I will not put every form to be large, and my interest is only in the 2 fields that I will insert)
function validaFormulario(){
var estoque_minimo;
var estoque_maximo;
estoque_minimo = $('#estoque_minimo').val();
estoque_maximo = $('#estoque_maximo').val();
if(estoque_minimo >= estoque_maximo){
alert('voce está fazendo isso errado...');
}
else{
$('#formCadastroProdutos').submit();
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><formid="formCadastroProdutos" method="POST" action="cadastra_produto.php">
<div class="form-group col-sm-4">
<label for="estoque_minimo">Estoque minimo</label>
<input type="number" class="form-control" id="estoque_minimo" name="estoque_minimo">
</div>
<div class="form-group col-sm-4">
<label for="estoque_maximo">Estoque máximo</label>
<input type="number" class="form-control" id="estoque_maximo" name="estoque_maximo">
</div>
<button onclick="validaFormulario()" id="btn_cadastra_produto" type="button" class="btn btn-primary">
Salvar
<span class="glyphicon glyphicon-floppy-disk"></span>
</button>
</form>
I did it that way, because I saw it in a similar post here ... I'm waiting for suggestions, thank you!