I have a disabled submit button that I can't seem to enable after BOTH a successful Google reCaptcha and checking there is text in an input box.
I'm using the HTML and 2 separate JS files below but the JS files only seem to work individually and not together. Is there a way to verify the reCaptcha and check the text box is filled together? I can't find any similar answer.
HTML:
<input type="text" name="em" ID="em" class="form-item input-address" placeholder="Email"></input>
<button type="submit" class="submit start" id="button1" alt="Submit" disabled="disabled"></button>
</br>
<?php foreach ($_POST as $key=> $value) { echo '
<p><strong>' . $key.':</strong> '.$value.'</p>'; } ?>
<div class="g-recaptcha" data-sitekey="{key}" data-callback="enableBtn"></div
recaptcha.js (this works on its own):
//Disable Button if No reCaptcha
$("#button1").prop("disabled", true);
function enableBtn() {
$("#button1").removeAttr('disabled');
}
What I'd like to do is also have the button disabled if there is no text in the input area. I have tried this and it works:
input.js (this also works on its own but not with recaptcha.js):
//Disable Button if Input Empty
$(document).ready(function() {
$('.input-address').keyup(function() {
var empty = false;
$('.input-address').each(function() {
if ($(this).val().length == 0) {
empty = true;
}
});
if (empty) {
$("#button1").prop("disabled", true);
} else {
$("#button1").removeAttr('disabled');
}
});
});