I have the following HTML textarea:
<textarea name="splitRepComments" cols="20" rows="3" ></textarea>
I have implemented a maxlength restriction using jQuery with the following function:
var max = 100;
$('#splitRepComments').bind("keypress", function(e) {
if (e.which < 0x20) {
// e.which < 0x20, then it's not a printable character
// e.which === 0 - Not a character
return; // Do nothing
}
if (this.value.length == max) {
e.preventDefault();
} else if (this.value.length > max) {
// Maximum exceeded
this.value = this.value.substring(0, max);
}
});
$('#splitRepComments').bind("paste", function(e) {
setTimeout(function() {
var e = jQuery.Event("keypress");
e.which = 50; // # Some key code value
$('#splitRepComments').trigger(e);
}, 100);
});
My challenge is that I need users to enter only 10 characters in each row (line) and then move to the next line.
This function should also adhere to the maxlength restriction of the textarea.
I have attempted a solution from SO, but it does not move input to the next line.
You can view my JSFiddle example for reference.