locked
Text Box Characters Counter RRS feed

  • Question

  • Im new to ms crm i need this sort of thing how to achieve this

    TextBox character count

    http://www.reconn.us/character_counter.html

    Monday, May 31, 2010 11:06 AM

Answers

  • Yeah, you need to add new field on the CRM Entity ..let's assume you call it remplace you need to put that on the form besides actual field..on form mark that field as readonly.....

    following is changed code based on this..hope this helps..

    // function parameters are: field - the string field, count - the field for remaining characters number and max - the maximum number of characters
    function CountLeft() {

    var max =50;
    var field = document.getElementById('name');

    var countfield = document.getElementById('remplace');


    var count = 0;

    // if the length of the string in the input field is greater than the max value, trim it
    if (field.value.length > max)
    field.value = field.value.substring(0, max);
    else
    // calculate the remaining characters
    count.value = max - field.value.length;

    countfield.value = count;


    }

    //name is accountname field)
    var element = document.getElementById('name');

    element.attachEvent("onkeyup", CountLeft());
    element.attachEvent("onkeydown", CountLeft());

    Monday, May 31, 2010 3:58 PM
    Answerer

All replies

  • open the CRM entity form and on the textbox change() event, write this code

    var length = crmForma.all.yourTextField.DataValue.Length;

    you can also do the same on the onSave() or onLoad() event, depending on your needs.


    Muhammad Ali Khan
    http://malikhan.wordpress.com

    Monday, May 31, 2010 11:10 AM
  • I need to achieve as this 

    http://www.reconn.us/character_counter.html

    how to display the remaining characters?

    should i place another field?

    please say clearly

    Monday, May 31, 2010 11:17 AM
  • you can use this same java script function against particular field and then put this code in Form On Load Event as follows

    for e.g assuming you want to put this check on account name field following example code for the same..

    // function parameters are: field - the string field, count - the field for remaining characters number and max - the maximum number of characters 
    function CountLeft() {
    
    var max =50;
    var field = document.getElementById('name'); 
    var count = 0;
    
    // if the length of the string in the input field is greater than the max value, trim it 
    if (field.value.length > max)
    field.value = field.value.substring(0, max);
    else
    // calculate the remaining characters 
    count.value = max - field.value.length;
    }
    
    //name is accountname field)
    var element = document.getElementById('name'); 
    
    element.attachEvent("onkeyup", CountLeft());
    element.attachEvent("onkeydown", CountLeft());
    
    Monday, May 31, 2010 11:21 AM
    Answerer
  • ok can i show the remaining characters dynamically? in readonly box beside that field?

    as in this example?

    http://www.reconn.us/character_counter.html

    Monday, May 31, 2010 12:18 PM
  • Yeah, you need to add new field on the CRM Entity ..let's assume you call it remplace you need to put that on the form besides actual field..on form mark that field as readonly.....

    following is changed code based on this..hope this helps..

    // function parameters are: field - the string field, count - the field for remaining characters number and max - the maximum number of characters
    function CountLeft() {

    var max =50;
    var field = document.getElementById('name');

    var countfield = document.getElementById('remplace');


    var count = 0;

    // if the length of the string in the input field is greater than the max value, trim it
    if (field.value.length > max)
    field.value = field.value.substring(0, max);
    else
    // calculate the remaining characters
    count.value = max - field.value.length;

    countfield.value = count;


    }

    //name is accountname field)
    var element = document.getElementById('name');

    element.attachEvent("onkeyup", CountLeft());
    element.attachEvent("onkeydown", CountLeft());

    Monday, May 31, 2010 3:58 PM
    Answerer