code 39

// Handle incoming messages function updateChatDisplay(subjectId, message) { var chatBox = document.getElementById('chatBox'); var messageElement = document.createElement('p'); var memberName = "Member " + subjectId; // Customize member name display messageElement.innerText = memberName + ": " + message; chatBox.appendChild(messageElement); chatBox.scrollTop = chatBox.scrollHeight; // Auto-scroll to the bottom } // Send a chat message function sendMessage() { var message = document.getElementById('chatInput').value; if (message.trim() !== "") { var messageData = { subjectId: myid, // Use the extracted ID message: message }; chatSocket.send(JSON.stringify(messageData)); updateChatDisplay(myid, message); // Display your own message immediately document.getElementById('chatInput').value = ''; // Clear the input box } } // Existing functions function receiveMessage(event) { if (event.data == "closeQSIWindow") { $("#qualFrame").hide(); experimentComplete(); } if (event.data == "popupConsent") { if (REQUEST_CONSENT) { requestConsent(); } } if (event.data == "payAMT") { if (IS_AMT) { payAMT(true, AMTBonus); } } } function showSubjectId(subjectId) { document.getElementById('member_id_display').innerText = "Your member ID is " + subjectId; } function initialize() { $("#survey_title").html(variables["title"]); window.addEventListener("message", receiveMessage, false); $("#qualFrame").attr("src", variables["survey_link"] + "&testId=" + seed + "&subjectId=" + myid); $("#qualFrame").height(variables["survey_height"]); $("#qualFrame").show(); showSubjectId(myid); connectWebSocket(); // Connect to WebSocket on initialization } }