Skip to content

Commit

Permalink
Add real-time character counter for text box input
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Satish Karwa committed Oct 21, 2024
1 parent f60dcfa commit 44f13db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
18 changes: 18 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ <h2>Have a play.</h2>
<a href="#" class="btn btn-primary download-pdf">Download PDF</a>
</div>

<div id="character-counter">Characters entered: <span>0</span></div>

<label class="checkbox-inline">
<input type="checkbox" id="auto-refresh" checked="checked"> Auto refresh on changes?
</label>
Expand Down Expand Up @@ -95,6 +97,22 @@ <h2>Have a play.</h2>
});
</script>

<script>
$(document).ready(function() {
const editor = ace.edit("editor");
const $charCount = $('#character-counter span');
const session = editor.getSession();

function updateCharCount() {
const charCount = session.getValue().length;
$charCount.text(charCount);
}

editor.on('change', updateCharCount);
$(window).on('load', updateCharCount);
});
</script>

<!-- Code editor -->

<script src="./examples/js/ace.js" type="text/javascript" charset="utf-8"></script>
Expand Down
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 44f13db

Please sign in to comment.