Trying to achieve something in javascript which I imagine can be written much more succinctly but is proving beyond me! See fiddle: http://jsfiddle.net/C2CNS/108/
Repetitive examples of:
<textarea id="input1" maxlength="100"></textarea>
<p><span id="charsLeft1">100</span> characters left</p>
With incremental numbers assigned and apended to #input and #charsleft. And JS:
var maxLen = 100;
$('input1').observe('keyup', function(evt) {
$('charsLeft1').update(maxLen - $('input1').value.length);
});
The final page will have MANY inputs with identical maxlength and individual counter PER textbox input. For each #input(number) the corresponding #charsleft(number) will be updated.
Since it is essentially the same function to the JS and same pattern to the HTML, rather than write the JS out longhand for each input counter (as shown in the fiddle link above): what would the elegant solution be that would keep track of all potential textboxes and corresponding counters? Thanks.