Skip to content

Instantly share code, notes, and snippets.

@femiyb
Created July 26, 2019 13:25
Show Gist options
  • Save femiyb/b142955f46703e7fdc7850fea969fc76 to your computer and use it in GitHub Desktop.
Save femiyb/b142955f46703e7fdc7850fea969fc76 to your computer and use it in GitHub Desktop.
<?php
function limit_text_area()
{
echo
"
<script>
jQuery(document).ready(function() {
jQuery('#company_info').on('keyup', function() {
var words = this.value.match(/\S+/g).length;
if (words > 500) {
// Split the string on first 500 words and rejoin on spaces
var trimmed = jQuery(this).val().split(/\s+/, 500).join(' ');
// Add a space at the end to keep new typing making new words
jQuery(this).val(trimmed + ' ');
}
else {
jQuery('#display_count').text(words);
jQuery('#word_left').text(500-words);
}
});
});
</script>
";
}
add_action('pmpro_checkout_before_submit_button', 'limit_text_area');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment