Forums

Character count in a textbox (CFv4)

SPABO 28 Sep, 2014
Read a lot of stuff, but I cannot get it working, pls advise where to find the solution...
SPABO 28 Sep, 2014
Bob, The "counter"works, but I'm puzzled with the "stop" event

This statement:
We need to add some more script in place of the innerHTML line previously shown:

Where do I put this script ????? What do you mean by innerHTML??
SPABO 28 Sep, 2014
Answer
1 Likes
I would sauy, as usual....

I missed the extra });, and not working

To make/complete teh final JS script.
window.addEvent('load', function() {
  // execute the check after each keystroke
  $('text_0').addEvent('keyup', function() {
    // set the maximum number of characters
    max_chars = 50;
    // get the current value of the input field
    current_value = $('text_0').value;
    // get current character count
    current_length = current_value.length;
    // calculate remaining chars
    remaining_chars = max_chars - current_length;
    // Change color if remaining chars are five or less
  if ( remaining_chars <= 5 ) {
    $('text_0').setStyle('background-color', '#F88');
    $('text_0').value
      = $('text_0').value.substring(0, max_chars-1);
    if ( remaining_chars <= 0 ) {
      remaining_chars = 0;
    }
  } else {
    $('text_0').setStyle('background-color', 'white');
  }
  $('counter').innerHTML = remaining_chars;
});
});


I will close this topic and again thanks for teh quick support.
Rgds
K
This topic is locked and no more replies can be posted.