I am facing an issue with my two counters that are used to track the number of characters in a message. Everything works fine until 160 characters, but after that point, the first counter stops at 0 instead of resetting back to 160 and decreasing from there. I need assistance in fixing this issue, please take a look at the code and screenshot provided.
Javascript
function textCounter(field,field2,maxlimit) {
var countfield = document.getElementById(field2);
if ( field.value.length > maxlimit ) {
countfield.value = 160 - field.value.length;
} else {
countfield.value = maxlimit - field.value.length;
}
}
HTML
<textarea class="text-input--underbar" placeholder="Enter Message" style="width: 100%; height: 100px;" onkeyup="textCounter(this,'counter',160);" ng-model="message" name="message" id="message"></textarea>
<br>
Remaining Characters : <input disabled maxlength="3" size="3" value="160" id="counter"> / SMS
<br>
Total SMS(s) : {{ (message.length - message.length % 160) / 160 + 1 }}
<br>
https://i.sstatic.net/3rPiC.png
ADDED
When the text area is empty, the Total SMS(s) shows NaN. How can I set an initial value for it in the expression I have used?