Web Programming Notes

December 22, 2008

TinyMCE Character Limit Example

Filed under: Javascript — admin @ 7:59 pm

TinyMCE Character Limit Example

Below is some code illustrating how to detect a character count on a TinyMCE wysiwyg control.  Enforcing the character limit can be done in a number of ways, the most basic being an alert.  The regular expression that removes the HTML tags is optional depending on whether they are relevant in the count.

<textarea style=”width: 600px;height:300px; ”></textarea>
<script>
function characterCount() {
    var text = tinyMCE.selectedInstance.getBody().innerHTML.replace(/(<([^>]+)>)/ig,\”\”);
     if (text.length > 300)
     {
          alert(”Character limit of 300 exceeded”);
     }
}
….
tinyMCE.init({
     theme : “advanced”,
     handle_event_callback : \”characterCount\”
});
….
</script>

1 Comment »

  1. PillSpot.org. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.Pillspot.org. Herbal-supplements@buy.online” rel=”nofollow”>.…

    Categories: Skin Care.Anxiety/Sleep Aid.Antidiabetic.Blood Pressure/Heart.Weight Loss.Pain Relief.Antiviral.Vitamins/Herbal Supplements.Antidepressants.Stomach.Mental HealthEye Care.Anti-allergic/Asthma.Mens Health.Antibiotics.Stop SmokingWomens H…

    Trackback by RICARDO — June 28, 2010 @ 2:34 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress