Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Real-Time Character Generator. #21

Merged
merged 2 commits into from
Oct 31, 2023
Merged
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
7 changes: 7 additions & 0 deletions Real Time Character Counter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This is a Real-Time Character Counter webpage built using HTML, CSS and JS only.

Working demonstration is given below:


https://github.com/urjabahad/Javascript-Projects/assets/127567639/a9fe3330-c826-473b-84fa-d21b6d44bde6

84 changes: 84 additions & 0 deletions Real Time Character Counter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Character Counter</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
background-color: sandybrown;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
margin: 0;
height: 100vh;
}

.container {
position: relative;
background-color: lightblue;
width: 400px;
padding: 20px;
border-radius: 15px;
margin: 5px;
box-shadow: 5px 5px 2px black;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
}

.textarea {
width: calc(100% - 20px);
height: 100px;
font-size: 20px;
resize: none;
box-sizing: border-box;
padding: 10px;
border-radius: 5px;
box-shadow: 5px 5px 2px black;
margin-bottom: 20px;
}

.counter-container {
display: flex;
justify-content: space-between;
width: calc(100% - 40px);
position: absolute;
bottom: 10px;
}

.counter-container p {
font-size: 20px;
margin: 0;
}

.total-counter {
color: slateblue;
}

.remaining-counter {
color: orangered;
}
</style>
</head>
<body>
<div class="container">
<h2>Real-Time Character Counter</h2>
<textarea id="textarea" class="textarea" placeholder="Please Write" maxlength="80"></textarea>
<div class="counter-container">
<p>
Total:
<span class="total-counter" id="total-counter">0</span>
</p>
<p>
Remaining:
<span class="remaining-counter" id="remaining-counter">80</span>
</p>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions Real Time Character Counter/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

document.addEventListener('DOMContentLoaded', function() {
const textarea = document.getElementById('textarea');
const totalCounter = document.getElementById('total-counter');
const remainingCounter = document.getElementById('remaining-counter');

textarea.addEventListener('input', function() {
const currentLength = textarea.value.length;
const maxLength = parseInt(textarea.getAttribute('maxlength'), 10);
totalCounter.textContent = currentLength;
remainingCounter.textContent = maxLength - currentLength;
});
});
Loading