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:
  • Lucas001 Profile Picture
    2,595 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
    17 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Pages

#1
M Bilal Khan Profile Picture

M Bilal Khan 139

#2
Mohsin Ali Profile Picture

Mohsin Ali 41

#3
11manish Profile Picture

11manish 19 Super User 2026 Season 2

Last 30 days Overall leaderboard