I would like to get the output in image 1, such that whenever I select book as itemcategory and type my code or barcode all data such as itemname and itemprice etc go under book category and new code/barcode.

What I currently have is in image2. If I input data again under book it just replaces the data already there, it doesn't add a new record based on category and (code/itembarcode)- both these are same.

function insertData(){
set(ref(db, "ItemByCategory/" +category.value),{
Code: barcode.value,
Category: category.value,
ItemName: itemname.value,
ItemPrice: itemprice.value,
})
.then(() =>{
alert("data stored successfully");
})
.catch((error)=>{
alert("unsuccessful, error"+error);
});
}
This is my insert code.
How do I go about this?
It sounds like your want:
set(ref(db, "ItemByCategory/" +category.value+"/"+barcode.value),{
Code: barcode.value,
Category: category.value,
ItemName: itemname.value,
ItemPrice: itemprice.value,
})
Or, with a ES6 template literal:
set(ref(db, `ItemByCategory/${category.value}/${barcode.value}`,{
...
})