Skip to content

Instantly share code, notes, and snippets.

@Terron23
Created October 16, 2017 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Terron23/4ac2b9a049a323533e851bda76baa8f3 to your computer and use it in GitHub Desktop.
Save Terron23/4ac2b9a049a323533e851bda76baa8f3 to your computer and use it in GitHub Desktop.
Simple Word Counter
<div class="container text-center">
<h1>Character Restrictor</h1>
<form>
<textarea name="count" rows="10" placeholder="Write Here" onkKeyDown="textCounter(this.form.count,this.form.countDisplay);" onKeyUp="textCounter(this.form.count,this.form.countDisplay);"></textarea><br>
<input class="text-center" readonly type="text" name="countDisplay" size="20" value="300"> Characters Remaining
</form>
</div>
var max = 300;
function textCounter(x, y) {
if(x.value.length > max) {
x.value = x.value.substring(0, max);
}
else {
y.value = max - x.value.length;
}
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
body {
margin-top: 50px;
padding-bottom: 50px;
background: beige;
}
textarea {
width: 100%;
padding: 10px;
font-size: 2em;
border: solid 8px gray;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment