1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
function LimiteTextArea(champs, nbLigne, nbCar) {
retour = 0;
retourPos = 0;
chaine = champs.value;
taille = chaine.length;
for (i=0; i<taille; i++) {
if (chaine.charCodeAt(i)==13) {
retour++; //on compte les retours à la ligne
retourPos = i + 2; //position du retour à la ligne
}
if ((i-retourPos)==nbCar) { //test limitant le nombre de caractères par ligne
if (event.keyCode!=13) {
champs.value = chaine.substr(0, chaine.length-1);
} else {
document.contrat.nbCar = i + nbCar;
}
}
}
if(retour>=nbLigne) { //test limitant le nombre de lignes
champs.value = chaine.substr(0, chaine.length-2);
}
} |