dasMeerIstBlau Posted November 19 Posted November 19 I would like to define a word / character limit for the message in the contact form so that a message can be a maximum of 400 characters long. Is there any help? Das Meer ist blau. is a brand design agency based in Hamburg, since 2014. Our range of services includes: - full service campaign - corporate design | Brand-design - classic advertising - web design - magazine design - packaging design - merchandising - development of pos materials
Solution Squareko Posted November 19 Solution Posted November 19 Add this code into code injection > footer <script> document.addEventListener("DOMContentLoaded", function () { var messageField = document.querySelector('textarea[name="message"]'); if (messageField) { messageField.addEventListener('input', function () { if (messageField.value.length > 400) { messageField.value = messageField.value.substring(0, 400); // Trims the message to 400 characters } // Optionally, display a warning if the message exceeds 400 characters var charCount = document.querySelector('#charCount'); if (!charCount) { charCount = document.createElement('div'); charCount.id = 'charCount'; messageField.parentNode.appendChild(charCount); } charCount.innerText = `${messageField.value.length}/400 characters`; }); } }); </script> note: var messageField = document.querySelector('textarea[name="message"]'); in this line you may have to change the class name according to your targeted field.
WasteLess Posted November 20 Posted November 20 Hi, I would like a solution for the same. I want to add a word limit to the "Message" category in my form. Please help.
Squareko Posted November 20 Posted November 20 In above code just change your field name class. Hopefully , you will get solution.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment