fantastic-garbanzo/chatroom.HTML
2023-08-28 21:06:36 +02:00

42 lines
1.2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Chatroom</title>
<style>
#chatbox {
width: 400px;
height: 300px;
border: 1px solid #ccc;
overflow-y: scroll;
}
</style>
</head>
<body>
<div id="chatbox"></div>
<input type="text" id="message" placeholder="Type your message">
<button id="send">Send</button>
<script>
const chatbox = document.getElementById('chatbox');
const messageInput = document.getElementById('message');
const sendButton = document.getElementById('send');
sendButton.addEventListener('click', sendMessage);
function sendMessage() {
const message = messageInput.value;
if (message.trim() === '') return;
const messageElement = document.createElement('div');
messageElement.textContent = message;
chatbox.appendChild(messageElement);
// Clear the input field
messageInput.value = '';
// Scroll to the bottom of the chatbox
chatbox.scrollTop = chatbox.scrollHeight;
}
</script>
</body>
</html>