Conflict with javascript code
-
I have inserted a reCAPTCHA on my custom html form and it works fine. However, when i added the following jquery code to validate that the email field and confirm email field match (which works as well) it over rides the reCAPTCHA and enables the submit button before the reCAPTCHA is completed. Any ideas would be hugely appreciated, many thanks
jQuery(document).ready(function($) {
$(document).ready(function(){
var $submitBtn = $(“#regform button[type=’submit’]”);
var $emailBox = $(“#email”);
var $confirmBox = $(“#confirmemail”);
var $errorMsg = $(‘<span id=”error_msg”>Emails do not match.</span>’);// This is incase the user hits refresh – some browsers will maintain
the disabled state of the button.
$submitBtn.removeAttr(“disabled”);function checkMatchingEmails(){
if($confirmBox.val() != “” && $emailBox.val != “”){
if( $confirmBox.val() != $emailBox.val() ){
$submitBtn.attr(“disabled”, “disabled”);
$errorMsg.insertAfter($confirmBox);
}
}
}function resetEmailError(){
$submitBtn.removeAttr(“disabled”);
var $errorCont = $(“#error_msg”);
if($errorCont.length > 0){
$errorCont.remove();
}
}$(“#confirmemail, #email”)
.on(“keydown”, function(e){
/* only check when the tab or enter keys are pressed
* to prevent the method from being called needlessly */
if(e.keyCode == 13 || e.keyCode == 9) {
checkMatchingEmails();
}
})
.on(“blur”, function(){
// also check when the element looses focus (clicks somewhere
else)
checkMatchingEmails();
})
.on(“focus”, function(){
// reset the error message when they go to make a change
resetEmailError();
})});
});
- The topic ‘Conflict with javascript code’ is closed to new replies.