Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ <h1>Textarea <span style="font-weight: normal;">awesomeness</span></h1>
<div class="row-fluid">
<div class="span6 offset3">
<div class="form-group">
<textarea id="countTextarea" placeholder="Start typing.." rows="4"></textarea>
<textarea id="countTextarea" placeholder="Start typing.." rows="4" maxlength="100"></textarea>
<p class="pull-right" style="color: rgb(248, 248, 248); margin-right: -20px;"><span id="characterCounter"></span> characters remaining</p>
</div>
</div>
</div>
Expand Down
21 changes: 13 additions & 8 deletions js/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
textareaCount.onkeypress = textareaCount.onkeyup = countCharacters;
countCharacters();