0
People I made a validation that when the user does not fill the input
my button gets disabled more wanted to display a message to inform the user that the field must be filled is possible to do this if yes could help me follow my code
HTML:
<form id="form-morte">
<div class="form-group row">
<div class="col-sm-6 col-xs-6">
<input type="number" name="idade" class="form-control" id="idade"
min="1" max="10" step="2"
placeholder="Idade"/>
</div>
<div class="col-sm-6 col-xs-6">
<div class="input-group">
<span class="input-group-addon">R$</span>
<input type="phone" name="salario" class="form-control money-mask" id="salario"
placeholder="Salário atual"/>
</div>
</div>
</div>
<ul class="list-inline list-unstyled">
{{--<li><input type="submit" class="btn-back-morte" value="Voltar"></li>--}}
<li><a class="btn-back-morte">voltar</a></li>
<li><input type="submit" class="btn-next-morte" id="btn-next-morte" value="Próximo"></li>
{{--<li><a class="btn-back-morte">voltar</a></li>
<li><a class="btn-next-morte next-morte" disabled="disable" tabindex="-1">Próximo</a></li>--}}
</ul>
</form>
JS:
$('.btn-next-morte').attr('disabled',true);
$('input').keyup(function(){
if ($('#idade').val().length > 0 && $('#salario').val().length > 0){
$('.btn-next-morte').attr('disabled', false);
}
/*if($(this).val().length !=0){
$('.btn-next-morte').attr('disabled', false);
}*/
else
{
$('.btn-next-morte').attr('disabled', true);
}
});
Add required="true" to the input (standard HTML message), if you want in javascript ai worth responding
– Felipe Duarte
@Felipeduarte if possible I would like it to be in js to take advantage of the code I’ve already made ^^
– Felipe Henrique
@Felipeduarte because the way it is the button is disabled but does not show any message to the user there is difficult to identify knows how is user neh hahahaha
– Felipe Henrique
You can do it by accessing the DOM and creating it at runtime (which I find a little expensive),or you can create hidden boxes and if the inputs are not filled in, you display them.
– Márcio Cristian
@Márciocristian and how would these Abels appear when the field is left unfilled and somen when fill
– Felipe Henrique