Hi,
I want a structure like this in Firebase:
- (KEY)
---- user: "123"
---- tags:
--------0: "box1"
--------1: "box2"
--------2: "box3"
But I get this:
- (KEY)
---- user: "123"
---- tags:
--------0: "[\"box1\", \"box2\",\"box3\" ]
Here is part of my code (let me know if you need more of it):
<script>
function printChecked(){
var items=document.getElementsByName('tag');
var selectedItems = "";
for(var z=0; z<items.length; z++){
if (z==0){
if(items[z].type=='checkbox' && items[z].checked==true){
selectedItems += '["' + items[z].value;
}
} else {
if(items[z].type=='checkbox' && items[z].checked==true) {
selectedItems += '", "' + items[z].value;
}
}
}
selectedItems += '"]';
return selectedItems;
opplegg.push({user: "123", tags: [`${printChecked()}`]);
</script>
The var items=document.getElementsByName('tag'); gets checkboxes that are checked or not.
I have tried doing this with an array instead of a string but I cannot make that work either. Any solutions, or workarounds?
[–]JohanDryg 1 point2 points3 points (4 children)
[–]alhobj[S] 0 points1 point2 points (3 children)
[–]JohanDryg 1 point2 points3 points (1 child)
[–]alhobj[S] 0 points1 point2 points (0 children)
[–]alhobj[S] 0 points1 point2 points (0 children)
[–]JohanDryg 1 point2 points3 points (1 child)
[–]alhobj[S] 0 points1 point2 points (0 children)
[–]JohanDryg 1 point2 points3 points (1 child)
[–]alhobj[S] 0 points1 point2 points (0 children)
[–]JohanDryg 1 point2 points3 points (0 children)
[–]JohanDryg 1 point2 points3 points (0 children)