jcadima
3/1/2017 - 10:17 PM

Disable submit button until all fields have been filled

Disable submit button until all fields have been filled

http://jsfiddle.net/tKQFN/


<form id="stripe_form">
Username<br />
<input type="text" id="user_input" name="username" /><br />
Password<br />
<input type="text" id="pass_input" name="password" /><br />
Confirm Password<br />
<input type="text" id="v_pass_input" name="v_password" /><br />
Email<br />
<input type="text" id="email" name="email" /><br />     
<input type="submit" id="register" disabled value="Register" />
</form>



<script>
  
$('#user_input, #pass_input, #v_pass_input, #email').bind('keyup', function() {
    if(allFilled()) {
       $('#register').removeAttr('disabled');
    }
    
});

function allFilled() {
    var filled = true;
    $('#stripe_form input').each(function() {
        if($(this).val() == '') {
           $('#register').attr('disabled', true);
        		filled = false;
        }
    });
    return filled;
}  
  
</script>