I am creating a form where the user will register for a website and in that form there are two input fields to help confirm the users password. I am trying to disable the submit button when the passwords are not matching and then reenable it when the passwords do match. I currently have the disable part working but I cannot reenable it.
I have tried looking at this post how to check confirm password field in form without reloading page but I couldn't figure out what I needed to do beyond what I currently have.
Code:
<form id="myform" action="process_registration.php" class="basic-grey" method="post">
<div>
<label for="firstName" id="firstName">* First Name:</label>
<input type="text" name="firstName" id="firstName" minlength=1 required />
</div>
<div>
<label for="lastName" id="lastName">* Last Name:</label>
<input type="text" name="lastName" id="lastName" minlength=1 required />
</div>
<div>
<label for="email" id="email">* Email:</label>
<input type="email" name="email" id="email" minlength=1 required />
</div>
<div>
<label for="username" id="usernameLabel">* Username:</label>
<input type="text" name="username" id="username" minlength=1 required />
</div>
<div>
<label for="password" id="passwordLabel">* Password:</label>
<input type="password" name="password" id="password" minlength=1 required />
</div>
<div>
<label for="passwordConfirm" id="passwordLabelConfirm">* Password Confirmation:</label>
<input type="password" name="passwordConfirm" id="passwordConfirm" minlength=1 required />
<span id="message"></span>
</div>
<div>
<input id="submit" type="submit" name="submit" value="Submit" />
</div>
</form>
<?php include ABSOLUTE_PATH . '_includes/footer.inc.php'; ?>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'>
</script>
<script src='https://cdn.jsdelivr.net/npm/jquery-validation@1.17.0/dist/jquery.validate.js'></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.min.js"></script>
<script>
$('form').validate();
</script>
<script>
$('#password, #passwordConfirm').on('keyup', function() {
if ($('#password').val() == $('#passwordConfirm').val()) {
$('#message').html('Matching').css('color', 'green');
$('submit').prop('disabled', false);
} else
$('#message').html('Not Matching').css('color', 'red');
$('submit').prop('disabled', true);
});
</script>