From de4dcf3f4d98b8450d39ba82364dac759982bbc6 Mon Sep 17 00:00:00 2001 From: Connor Krammer Date: Sat, 5 Apr 2014 16:35:42 -0600 Subject: [PATCH] Fix problems with character-limit demo --- index.html | 3 ++- js/demo.js | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 5e7f7f4..a0d55d9 100755 --- a/index.html +++ b/index.html @@ -159,7 +159,8 @@

Textarea awesomeness

- + +

characters remaining

diff --git a/js/demo.js b/js/demo.js index bfad77a..09734d6 100644 --- a/js/demo.js +++ b/js/demo.js @@ -137,13 +137,18 @@ document.getElementById("saveButton").onclick = function() { } var textareaCount = document.getElementById("countTextarea"); -textareaCount.onkeyup = function() { - //console.log(this.value.length); +var characterCounter = document.getElementById("characterCounter"); + +function countCharacters() { var prgjs = progressJs("#countTextarea").setOptions({ theme: 'blackRadiusInputs' }).start(); + + var length = textareaCount.value.length; + var maxLength = textareaCount.getAttribute("maxlength"); + var progress = length / maxLength * 100; + + prgjs.set(progress); + characterCounter.textContent = maxLength - length; +} - if (this.value.length <= 100) { - prgjs.set(this.value.length); - } else { - this.value = this.value.substring(0 ,100); - } -}; \ No newline at end of file +textareaCount.onkeypress = textareaCount.onkeyup = countCharacters; +countCharacters(); \ No newline at end of file