0

How do I enable and Disable the button with AJAX get error admin.php:15 Uncaught ReferenceError: $ is not defined

function validate() {
    // Find the validation image div
    var validationElement = document.getElementById('nameValidation');
    // Get the form values
    var password1 = document.forms["Admin"]["password1"].value;
    var password2 = document.forms["Admin"]["password2"].value;
    // Reset the validation element styles

    validationElement.style.display = 'none';
    validationElement.className = 'validation-image';
    // Check if password2 isn't null or undefined or empty
    $('#savepasswd').prop('disabled', true);
    if (password2) {
        // Show the validation element
        validationElement.style.display = 'inline-block';
        // Choose which class to add to the element
        $('#savepasswd').removeAttr('disabled');
        validationElement.className += 
            (password1 == password2 ? ' validation-success' : ' validation-error');
    }
}

PHP code.

$msg .= "  <td><input type=\"submit\" name=\"savepasswd\"  id=\"savepasswd\" value=\"Save Access\" class=\"inputadmin\"></td>\n";
1
  • 2
    You forgot to load JQuery. Commented Feb 23, 2016 at 1:10

1 Answer 1

1

You apparently don't have jQuery loaded. You don't need it just for this, you can use plain Javascript.

To disable the button:

document.getElementById('savepasswd').disabled = true;

To enable the button:

document.getElementById('savepasswd').disabled = false;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.