2
The code I have to validate the button doesn’t work:
$(document).ready(function(){
$("#sendCat").prop('disabled', true);
if ($('#cat').val()!= "") {
$("#sendCat").prop('disabled', false);
}
});
<form action="proc_cat.php" method="post">
<div class="input-field col s5">
<input id="cat" name="name_cat" type="text">
<label>Categoria:</label>
</div>
<div class="input-field col s5">
<input name="sub_cat" type="text">
<label>SubCategoria</label>
</div>
<div class="input-field col s2">
<button id="sendCat" class="btn">Adicionar</button>
</div>
</form>
You have to have an event receiver to check for changes, that’s what you’re looking for?
$('#cat').on('change', function(){...
– Sergio
@Sergio, it worked, however have two problems with this method, when I delete data from the input field and becomes empty, the button does not disable again and is only enabled when I exit the input, it would be interesting to enable the button to type the first letter in the input.
– Henrique Mendes Silveira Rodri
I answered this in my reply below, using the event
input
, take a look.– Sergio