I want to use keystroke events to check the limit of a rich text box . I am using Input field for that. As we are not able to directly use events for inputfield for rich text box . Is there a way so that i can use events on inputfield which is holding rich text ??

 function testMe(e , f){
     if(f != '0'){

<apex:actionFunction name="runMeApex" action="{!testAction}" rerender="Details">

<apex:inputText value="{!w.name}" onkeyup="testMe(event);" />

you can use action function to check the limit of a rich text box using key up event. here i have only given a deme code if you want to run you code then either you can crate you own controller or you can use java script.

  • For <apex:inputText> events can be placed directly I am asking can we fire events on <apex:inputField> ?? – vishal tandon Jul 7 '15 at 9:16
  • yes, events can be directly placed in <apex:inputfield> – Ajay Dubedi Jul 7 '15 at 9:26
  • i have tried using a simple function to display an alert message ... it was working fine for everything but not for rich text area... – vishal tandon Jul 7 '15 at 10:45

You can use plain vannila Javascript to do this.

The Visualforce portion will look like

<apex:outputPanel id="myTASize12">{!LEN(i_objRMADeviceDetail.Problem_Description__c)} / 250</apex:outputPanel>                                                                                            
<apex:inputField id="ProbDescriptFld" value="{!i_objRMADeviceDetail.Problem_Description__c}" label="Problem Description:" html-maxlength="250"onchange="ShowCharCount(this, 250, '{!$Component.myTASize12}');" onmousedown="ShowCharCount(this, 250, '{!$Component.myTASize12}');" onkeyup="ShowCharCount(this, 250, '{!$Component.myTASize12}');" onkeydown="ShowCharCount(this, 250, '{!$Component.myTASize12}');" onclick="ShowCharCount(this, 250, '{!$Component.myTASize12}');"/>

The Javascript method look like

function ShowCharCount(myTA,maxSize,SizeLabel) {                  
    if(myTA.value.length > maxSize)
        myTA.value = myTA.value.substring(0,maxSize);
    document.getElementById(SizeLabel).innerHTML = myTA.value.length + ' / 250';

The user won't be able to enter more than 250 characters in the input field. We are showing the counter on top of it aswell.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.