-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs_program_05.html
More file actions
43 lines (43 loc) · 1.02 KB
/
js_program_05.html
File metadata and controls
43 lines (43 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html>
<head>
<title>Main Program - Word & Character Counter</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 40px;
background-color: #f0f0f0;
}
textarea {
width: 100%;
height: 150px;
padding: 10px;
font-size: 16px;
border-radius: 6px;
border: 1px solid #ccc;
margin-bottom: 10px;
}
.counter {
font-size: 18px;
color: #333;
}
</style>
</head>
<body>
<h2>Main Program: Live Word and Character Counter</h2>
<textarea id="mainText" placeholder="Start typing here..."></textarea>
<div class="counter">
Characters: <span id="mainCharCount">0</span><br>
Words: <span id="mainWordCount">0</span>
</div>
<script>
document.getElementById("mainText").addEventListener("input", function () {
const text = this.value;
document.getElementById("mainCharCount").innerText = text.length;
const trimmed = text.trim();
const wordCount = trimmed === "" ? 0 : trimmed.split(/\s+/).length;
document.getElementById("mainWordCount").innerText = wordCount;
});
</script>
</body>
</html