If I understand correctly that you want to release a link being released after the data is filled in, do the following. Change your HTML to:
<form id="formulario">
<label>Usuário</label>
<input required id="usuario">
<label>Senha</label>
<input id="senha" required>
<button type="button" id="login">Login</button>
</form>
<a id="seu_link" class="disabled">Seu link Bloqueado</a>
And, with the jQuery
, do the following:
$(function(){
$('#login').click(function(e){
if ($("#usuario").is(':valid') && $("#senha").is(':valid')) {
// Ação ao submter o formulário
$("#seu_link").removeClass('disabled');
} else {
e.preventDefault();
}
});
$(document).on('.disabled', 'click', function(){ return false; });
});
So you are checking whether the input is filled in.
Note: The verification with is(':valid')
or is(':invalid')
is only possible if the input has the attribute required
or the pattern
.
Follow the example of Jsfiddle
In case, as I imagined that maybe you, instead of wanting to unlock a link, unlock the button that makes the submit
.
So I wrote the following code.
Form:
<form id="formulario">
<label>Usuário</label>
<input required id="usuario">
<label>Senha</label>
<input id="senha" required>
<button type="button" id="login" disabled>Login</button>
</form>
Jquery:
$(function(){
var $btn = $("#login");
$("#usuario, #senha").on('keyup', function(){
if ($('#usuario').is(':valid') && $('#senha').is(':valid')) {
$btn.attr({disabled:false});
} else {
$btn.attr({disabled: true});
}
});
});
You can see this second example in this Jsfiddle
I think that in this second way, the usability is greater
+1 I did not know! It seems to be interesting
– Wallace Maxters