Created
October 20, 2011 04:09
-
-
Save mark-cooper/1300393 to your computer and use it in GitHub Desktop.
Display a count of characters and words from input fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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