I used to have simple HTML code block to add the character count and to limit a number of characters allowed in the text area of the contact form. However, it looks like sometime this summer Squarespace updated the variables for the contact forms which broke the code.
Is there a list of new variables anywhere? I think messageField is the problem but it could be anything else at this point.
Please help.
Here's what it looked like: <script>
document.addEventListener("DOMContentLoaded", function() {
var messageField = document.querySelector("#message");
var maxLength = 200; messageField.setAttribute("maxlength", maxLength);
var counter = document.createElement("div"); counter.classList.add("char-counter"); counter.innerHTML = "<span>" + maxLength + "</span> characters left"; messageField.parentNode.insertBefore(counter, messageField.nextSibling); messageField.addEventListener("input", function() {
var currentLength = messageField.value.length;
var remaining = maxLength - currentLength; counter.querySelector("span").innerHTML = remaining; if (remaining < 0) { messageField.classList.add("is-error"); } else { messageField.classList.remove("is-error");
}
});
});
</script>