-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (21 loc) · 696 Bytes
/
Copy pathscript.js
File metadata and controls
26 lines (21 loc) · 696 Bytes
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
const userInput = document.getElementById('userInput');
const submitBtn = document.getElementById('submitBtn');
const output = document.getElementById('output');
submitBtn.addEventListener('click', handleSubmit);
userInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
handleSubmit();
}
});
function handleSubmit() {
const inputValue = userInput.value.trim();
if (inputValue === '') {
output.textContent = 'Please enter some text.';
output.className = 'output error';
return;
}
output.textContent = `You sent: ${inputValue}`;
output.className = 'output success';
userInput.value = '';
userInput.focus();
}