I have to control the textarea
at the validation of the screen.
When a line contains more than 78 characters or if you have more than 5 lines entered in the textarea
, I have to stay on the screen and display an error message.
<body>
<form name="newForm">
<textarea id="myArea" cols="79" rows="5" onkeypress="upload(event);"></textarea>
</form>
</body>
<script>
var counter1 = 0;
var counterrow = 0;
var old = 0;
var limit = 78;
function upload(e) {
old = counter1;
var myVal = document.getElementById("myArea");
counter1 = myVal.value.length + 1;
var code = (e.keyCode ? e.keyCode : e.which);
if (counter1 <= 78) {
counter1 = counter1 - (counterrow * limit);
}
if (counter1 <= limit && counterrow <= 5) {
if (code == 13) { //Enter keycode
counterrow++;
counter1 = 0;
}
} else if (counter1 > limit && counterrow <= 5) {
alert('cant xceed 78 Char/row : validations');
if (code == 13) { //Enter keycode
counterrow++;
counter1 = 0;
}
} else if (counterrow > 5) {
alert('cant exceed 5 : validation');
}
}
</script>