I've tried to solve this by my own but I've been struggling a lot. I've got 5 inputs that are stick together (they actually look like a textarea), and what I'm trying to do, is to fix a limit of the number of characters in each input, and when we reach the char limit, the cursor automatically focus on the next input and paste the last word that we couldn't entirely write in the last input before and if we erase few characters of this word, its goes back to the previous input (only if the characters limits isn't reached). Here's what I tried to do:
function passage(enCours, suivant, limite){
if (enCours.value.length == limite)
{
$('#cmzTextLines'+suivant).focus();
}
}
function test(now, suivant){
var text = $('#cmzTextLines'+now).val();
var textSuivant = $('#cmzTextLines'+suivant).val();
//var lines = text.split("\n");
for (var i = 0; i < text.length; i++) {
if (text[i].length <= maxLength) continue;
var j = 0; space = maxLength;
while (j++ <= maxLength) {
if (text[i].charAt(j) === " ") space = j;
}
textSuivant = text[i].substring(space + 1) + (textSuivant || "");
text[i] = text[i].substring(0, space);
}
}
The HTML:
<input type="text" class="form-control" id="cmzTextLines1" name="cmzTextLines1" onkeyup="passage(this, 2, 30); test(1, 2);">
<input type="text" class="form-control" id="cmzTextLines2" name="cmzTextLines2"
onkeyup="passage(this, 3, 30); test(2, 3);">