...
Code Block |
---|
window.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("message-form");
const messageInput = document.getElementById("message-input");
form.addEventListener("submit", (event) => {
event.preventDefault(); // Prevent form submission
const message = messageInput.value;
// Display sent message
const sentMessageDiv = document.createElement("div");
sentMessageDiv.className = "message sent";
sentMessageDiv.textContent = message;
messagesContainer.appendChild(sentMessageDiv);
const currentMessageDiv = document.createElement("div");
currentMessageDiv.className = "message received";
currentMessageSpan = document.createElement("span");
currentMessageDiv.appendChild(currentMessageSpan);
messagesContainer.appendChild(currentMessageDiv);
chatbotClient.sendMessage(message);
messageInput.value = "";
});
}); |
...