Home

How To Disable Submit Button Until A Form Is Filled

Published on 6th Feb 2018 in JavaScript

If you trying to disable a submit button until a form is filled then you can do this easily using Jquery. With help of Jquery you can disable a submit button until last text field is filled out and after that button is enabled to submit a form data.

HTML

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

JAVASCRIPT

<script>
(function() {
    $('form > input').keyup(function() {

        var empty = false;
        $('form > input').each(function() {
            if ($(this).val() == '') {
                empty = true;
            }
        });

        if (empty) {
            $('#register').attr('disabled', 'disabled');
        } else {
            $('#register').removeAttr('disabled');
        }
    });
})()
</script>

Share It
Stay Connected
Like Us on Facebook