Skip to content

Instantly share code, notes, and snippets.

@mark-cooper
Created October 20, 2011 04:09
Show Gist options
  • Save mark-cooper/1300393 to your computer and use it in GitHub Desktop.
Save mark-cooper/1300393 to your computer and use it in GitHub Desktop.
Display a count of characters and words from input fields
// CHARACTER / WORD counter demo - uses Jquery
$(document).ready(function () {
// input with #characters and accompanying span with #c_length
$("#characters").keyup(function() {
$('#c_length').html($(this).val().length);
});
// input with #words and accompanying span with #w_length
$("#words").keyup(function() {
var matches = $('#words').val().match(/\b[A-Za-z]\w*/g);
matches = (matches) ? matches.length : 0 ;
$('#w_length').html(matches);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment