Syllable Counter
HTML
<textarea rows="8" cols="3" class="alignright" name="set_a_syllable_count" readonly="readonly" /></textarea>
<textarea rows="8" cols="30" name="set_a">i would appreciate
any help
at all</textarea>
CSS
* {
font-family:Helvetica;
font-size:1em;
}
body {
margin:30px;
}
.alignright { text-align: right;}
textarea {float:left; }
JavaScript
function $count_how_many_syllables($input) {
$("[name=set_" + $input + "]").keyup(function () {
var $content = this.value;
var word = $content;
word = word.toLowerCase();
if (word.length <= 3) {
word = 1;
}
if (word.length == 0) {
return 0;
}
word = word.replace(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, '');
word = word.replace(/^y/, '');
word = word.match(/[aeiouy]{1,2}/g);
var $syllable_count = word;
var $result = $syllable_count;
$("[name=set_" + $input + "_syllable_count]").val($result);
});
}
$(function () {
$count_how_many_syllables("a");
});