I am trying to auto-capitalize the first character of a textarea/input that the user inputs. The first attempt looked like this:
$(document).ready(function() {
You can use a jQuery function:
$.fn.CapitalizeFirst = function () {
return this.each(function () {
$(this).on('keydown', function (event) {
if (this.selectionStart == 0 && event.keyCode >= 65 && event.keyCode <= 90 && !(event.shiftKey) && !(event.ctrlKey) && !(event.metaKey) && !(event.altKey)) {
var $t = $(this);
event.preventDefault();
var char = String.fromCharCode(event.keyCode);
$t.val(char + $t.val().slice(this.selectionEnd));
this.setSelectionRange(1, 1);
}
});
});
};