If I understand correctly that you want to release a link being released after the completed data, 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 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 if the input is filled.
Note : Verification with is(':valid')
or is(':invalid')
is only possible if the input has the attribute required
or pattern
.
Follow the example of JSFiddle
In this case, how did I imagine that maybe you, instead of wanting to unlock a link, unlock the button that makes 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 of this second form, the usability is greater