function sendMessage() { const userInput = document.getElementById('user-input').value; const chatOutput = document.getElementById('chat-output'); if (userInput.trim() === "") { return; } // Display user message chatOutput.innerHTML += `
You: ${userInput}
`; // Simulate chatbot response (use REST API call here for real chatbot) fetch('https://your-chatbot-api.com/message', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: userInput }) }) .then(response => response.json()) .then(data => { chatOutput.innerHTML += `
Chatbot: ${data.reply}
`; chatOutput.scrollTop = chatOutput.scrollHeight; // Auto-scroll }) .catch(error => { console.error('Error:', error); chatOutput.innerHTML += `
Chatbot: Sorry, something went wrong.
`; }); document.getElementById('user-input').value = ''; // Clear input field }