Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
I create a messaging app using firebase but there is a very confusing error

I created a simple messaging website but faced a difficult problem: A and B each have two chat groups as shown in the picture, when B switches to B&D group and then A messages in A&B but that message pops up in the B&D group??!!
This is my Javascript code:

const app = initializeApp(firebaseConfig);
const database = getDatabase();

var message = document.getElementById("input"); //input
var btn = document.getElementById("send"); //send button

var order = document.getElementsByClassName("chat-head"); //class name of chat group
var room_name = "a&b"; //A&B is default group when open web (example)

function send(){
    push(ref(database, room_name),{
        Message: message.value
    });
    message.value = "";
}
function receive(){
    onValue(ref(database, room_name), snapshot => {
        snapshot.forEach(element => {
            //print name of chat group and messages in it
            console.log(room_name, element.val())
        });
    });
}
function chatHead(){
    //set color the chat group which I choose is red
    order[0].style.backgroundColor = "red";
    for(let i = 0; i < order.length; i++) {
        order[i].addEventListener("click", () => {
            order[i].style.backgroundColor = "red";
            for(let j = 0; j < order.length; j++){
                if(j != i){
                    order[j].style.backgroundColor = "white"; // and others is white
                }
            }
            room_name = order[i].id;
            receive();
        });
    }
}
chatHead();
window.onload = receive();
btn.addEventListener("click", send);

picture1

picture2

picture3

messages

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!