Selector
Selects only corresponding letters or excludes only corresponding letters
by Marcus Baptiste
HTML
<textarea id="words"></textarea>
<br>
<button id="btncalc" onclick="calc();">Calculate</button>
<br>
<br>
<input type="checkbox" id="opt">Remove Corresponding
<br>
<p id="dispNewText">New Text</p>
JavaScript
$(document).ready(function () {
$("#btncalc").click(function () {
var testtext = $(this).siblings("#words").val(),
testchar = 0,
newtext = "",
exclusion = false;
if ($(this).siblings("#opt").is(":checked")) {
exclusion = true;
}
for (i = 0; i < testtext.length; i++) {
testchar = testtext.charCodeAt(i);
switch (testchar) {
case 107: //corresponding letters
case 108:
case 109:
case 111:
case 112:
case 113:
case 101:
case 102:
case 103:
if (exclusion) {
newtext += "";
} else {
newtext += testtext[i];
}
break;
case 32: //special characters ' ( ) . and space
case 39:
case 40:
case 41:
case 46:
newtext += testtext[i];
break;
default:
if (exclusion) {
newtext += testtext[i];
} else {
newtext += "";
}
}
}
$(this).siblings("#dispNewText").text(newtext);
});
});