web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Adding character count...
Power Pages
Unanswered

Adding character counter to a form field

(0) ShareShare
ReportReport
Posted on by 323

Hi,

 

We have a requirement to add a character counter to a form field in Power pages. How can we achieve this?

 

prathyoo_0-1714742524958.png

 

Example, like this - 

prathyoo_1-1714742586000.png

 

Categories:
I have the same question (0)
  • Lucas001 Profile Picture
    2,527 Super User 2026 Season 1 on at

    Hi @prathyoo,

     

    I think that this codepen will be helpfull: https://codepen.io/btn-ninja/pen/QWGRRZE

    You probably need to add the p tag by using jQuery and insert it below your field.

     

    The JS should also work fine inside your page.

    I am not aware of an OOB Solution for your requirement.

    --------------------------------------------------------------------------------------

    Hope that helps.

    If the post solves your problem, please mark it as solution. If it helps, consider a thumbs up.

  • Fubar Profile Picture
    8,487 Super User 2026 Season 1 on at

    This is one I did not that long ago, you just call it and pass it the schema name of the field, it will also check if someone is pasting too much text in (if there's browser support) - no warranty is provided.

    function addCharacterCounter(fieldName){
     //debugger;
     let maxLength = $("#"+fieldName).attr("maxlength");
     let formattedMaxLength = Number(maxLength).toLocaleString("en-US");
     let currentLength = $("#"+fieldName).val().length.toLocaleString("en-US");
     $( "<p style='float: right;'><span id='"+fieldName+"CharCounter'>"+currentLength+"</span><span>/"+formattedMaxLength+"</span></p>" ).insertAfter($("#"+fieldName))
    	
     // update counter on key event
     $( "#"+fieldName ).on( "keyup", function(event) {
     let fieldId = event.currentTarget.id;
     let newLength = $("#"+fieldId).val().length.toLocaleString("en-US") ;		
     $("#"+fieldId+"CharCounter").text(newLength);		
     });
    	
    	
     // put message on screen if attempt to paste too much text
     // also takes into account pasting to replace selected text
     const target = document.getElementById(fieldName);
     target.addEventListener("paste", (e) => {
     try{
     	 let paste = (e.clipboardData || window.clipboardData).getData("text");
    	 let clipLength = paste.length;
    	 let existingLength = $("#"+e.currentTarget.id).val().length;		
    	 let maxLength = Number($("#"+e.currentTarget.id).attr("maxlength"));
    
    	 // if there is text that is currently selected that will be replaced 
     // get the length of the selection
    	 let selectedTextLength = window.getSelection().toString().length;
    		
     	 if((clipLength+existingLength-selectedTextLength) > maxLength ){
    	 alert("Unable to paste content - content will exceed the maximum length for the field");
     return false;
    	 }
     }
     catch(err){
    	 //do nothing
     }		
    		
     return true		
     
     });
    }

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Pages

#1
Lucas001 Profile Picture

Lucas001 17 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 12

#2
CN-06091549-0 Profile Picture

CN-06091549-0 12

Last 30 days Overall leaderboard