-
Notifications
You must be signed in to change notification settings - Fork 0
/
capitalize.html
32 lines (30 loc) · 1.05 KB
/
capitalize.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Capitalize Words</title>
</head>
<body>
<h1>Capitalize First Letter of Each Word</h1>
<form id="textForm">
<label for="inputText">Enter your text:</label>
<input type="text" id="inputText" name="inputText" required>
<button type="submit">Capitalize</button>
</form>
<div id="output"></div>
<script>
function capitalizeWords(str) {
return str.replace(/\b\w/g, function(char) {
return char.toUpperCase();
});
}
document.getElementById('textForm').addEventListener('submit', function(event) {
event.preventDefault();
const inputText = document.getElementById('inputText').value;
const capitalizedText = capitalizeWords(inputText);
document.getElementById('output').innerText = capitalizedText;
});
</script>
</body>
</html>