Why am I not able to set cookies on my device?

I am not able to set javascript cookies on my device for some reason. I am using this code:

<!DOCTYPE html>  
<html>  
<head>  
</head>  
<body>  
<input type="button" value="setCookie" onclick="setCookie()">  
<input type="button" value="getCookie" onclick="getCookie()">  
    <script>  
    function setCookie()  
    {  
        document.cookie="username=Duke Martin";  
    }  
    function getCookie()  
    {  
        if(document.cookie.length!=0)  
        {  
        alert(document.cookie);  
        }  
        else  
        {  
        alert("Cookie not available");  
        }  
    }  
    </script>  
  
</body>  
</html>

I have tried setting different cookie codes from different websites on different browsers , but none of them work. The thing is that even codes from w3schools which set cookies on my friend’s device are not able to set cookies on my device .Could you please tell me if there is some sort of debugger so that I can make cookies work?
P.S.: I have tried over 15 cookie codes in the past 3 hours but I am not able to set any cookies!
Thanks in advance!

How to hide scroll to bottom button in a page that do not have vertical scrollbar?

I made a scroll to top and bottom button, which allow users to scroll to top and scroll to bottom when it is clicked. As for now , if the button is scroll-to-top icon/button, the button will appear in pages that contain vertical scrollbar only and disappear in pages that do not have vertical scrollbar. However , if the button changes to scroll-to-bottom icon/ button, the button will appear in both pages that contain scrollbar and no scrollbar. How do i make scroll to bottom button disappear in a page that do not contain vertical scrollbar? Hope someone could help me on this.

ScrollToTop.vue

<template>

      <div v-scroll="onScroll" >
        <v-btn v-if = "!isVisible"
            fab fixed bottom right color="primary" @click="toBottom">
            <v-icon>mdi-arrow-down-bold-box-outline</v-icon>
        </v-btn>

        <v-btn v-else
            fab fixed bottom right color="primary" @click="toTop">
            <v-icon>mdi-arrow-up-bold-box-outline</v-icon>
        </v-btn>
      </div>
</template>

<script>

export default{

    data () {
        return {
        isVisible: false,
        position: 0,


    }
  },
   methods: {
    onScroll () {
      this.isVisible = window.scrollY > 50
    },
    toTop () {
      this.position = window.scrollY
      window.scrollTo({
        top: 0,
        left: 0,
        behavior: 'smooth'
      })
    },
    toBottom(){
      let pos = this.position > 0 ? this.position : window.pageYOffset

      window.scrollTo({
        top: pos,
        behavior: 'smooth'
      })
    },

  }
}

</script>

Default.vue

<script>

export default {
    name: "DefaultLayout",
    data() {
        return {

            hasScroll: false
        };
    },
    methods: {
        hasVerticalScroll() {
          this.hasScroll = document.body.offsetHeight > window.innerHeight;
    }
  }
}
</script>

<template>
  <v-app dark v-scroll="hasVerticalScroll">
     <ScrollToTop v-if="hasScroll"></ScrollToTop>
  </v-app>
</template>


ReactNative FlatList nested inside FlatList

I want to do something like this https://i.stack.imgur.com/SlbKX.png.
If you need more information,please let me know! Hope someone can help me!

`const DATA=[[1,name1,...],[2,name2,...]...];// Data like [[...],[...],...]
<FlatList
    data={DATA}  
    keyExtractor={(outterItem)=>outterItem.key}
    renderItem={({outterItem})=>(                                                                          
    <View>
        <FlatList
              horizontal={true}
              data={outterItem}
              keyExtractor={(innerItem)=>innerItem.key}
              renderItem={({InnerItem})=>(  
                  <View style={styles.box}>
                      <Text style={styles.Text}>{InnerItem}</Text>
                   </View>
              )}   
         />
    </View>

  />



`

How can I load text file in javascript using fileReader? [duplicate]

I’m trying to load simple text file in javascript, unfortunately with no success.
my code is:

var my_text:any;
var my_file:File = new File([], "C:\Users\riki7\Downloads\classes.txt");
var reader = new FileReader();
reader.onload = function() {
  my_text = reader.result;
};
reader.readAsText(my_file);
alert(my_text);

after this code runs, I would expect to see classes.txt file content in pop-up alert, instead I get ‘undefined’.
my file contains a, b, c.

does anyone know what is my problem? maybe the first parameter for File() constructor?

Event Listener triggers only one time

I am working on Javascript. This may seem a simple query but i have searched and tried everything I could. That’s why posting here now. So basically I have two tables. table A contains variables and magnitude. Table B has input field where equation is entered and the adjacent cell calculates and prints the result. The event listener (input) works completely fine for first equation but for further equations it doesn’t print calculation.
PS: both tables are dynamically created.

html {
    overflow-x: hidden;
} body{
    margin-top:0 ;
    margin-left: 0;
    
}
.popup-table {
    margin-top: 230px;
    margin-left: 30px;
    display: none;
    position: fixed;
    padding-left: 18px;
    z-index: 1;
    left: 80;
    top: 50;
    width: 60%;
    height: 60%;
    overflow: auto;
    background-color: white;
    border: 4px solid #04AA;
}

#mytable_2{
    margin-top: 20px;
    border-style: none;
}
.top-form {

    margin-top: 10px 20px;
    display: inline;
}

.top-form h3 {
    color: rgb(31, 31, 39);
    font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;

}

.close {


    background-color: white;
    margin-left: 150px;
    height: 4px;
    width: 8px;

    color: black;
    font-size: 34px;
    transition-duration: 0.4s;


}

.close:hover,
.close:focus {

    text-decoration: none;
    cursor: pointer;
    background-color: #04AA;
    color: white;
}

.btn-class1 {

    color: white;
    border: none;
    background-color: red;
    padding: 16px 16px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
    margin: 6px ;
    transition-duration: 0.4s;
    cursor: pointer;

}

.btn-class2 {

    color: white;
    border: none;
    background-color: #04AA;
    padding: 18px 16px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 20px;
    margin: 20px 20px 5px 5px;
    transition-duration: 0.4s;
    cursor: pointer;

}

.btn-class1:hover {
    color: black;
    background-color: bisque;
}

.btn-class2:hover {
    color: black;
    background-color: bisque;
}

#table-data {
    font-family: Arial, Helvetica, sans-serif;
    width: 90%;
}
#table-data2 {
    font-family: Arial, Helvetica, sans-serif;
    width: 90%;
}

#table-data th {
    padding-top: 12px;
    padding-bottom: 12px;
    text-align: center;
    background-color: #04AA;
    color: white;
    padding: 8px;

}

#table-data2 th {
    padding-top: 12px;
    padding-bottom: 12px;
    text-align: center;
    background-color: #04AA;
    color: white;
    padding: 8px;

}


#table-data tr:nth-child(even) {
    background-color: hsl(214, 80%, 54%);
}

#table-data tr:nth-child(odd) {
    background-color: grey;
}

#table-data tr {
    border: 1px solid grey;

}

#table-data2 tr{
    border: 1px solid grey;
}

.popup-table {
    width: 34%;
}
.popup-table h3 {
    text-align: center;
    font-size: 25px;
    color: rgb(31, 31, 39)
}
    <div class="popup-table" id="mytable">

        <div class=" top-form">
            &nbsp; <h3> Caclulation Table <span class="close">&times;</span></h3>

        </div>
        <table id="table-data">
            <tr>
                <th>Variables</th>
                <th>Magnitude</th>
                <th>Unit</th>
                <th>Action</th>
            </tr>
        </table>


        <div class="popup-table2" id="mytable_2">
            <table id="table-data2">
                <tr>
                    <th>Calculations</th>
                    <th>Magnitude</th>
                    <th>Unit</th>
                    <th>Action</th>
                </tr>
                
            </table>

        </div>
        <button type="button" class="btn-class2" id="btn-variable">+Variable</button>
        <button type="button" class="btn-class2" id="btn-calculation"> +Calculation</button>
    </div>
var blockmessage = document.getElementById("mytable");
var blockmessage2 = document.getElementById("mytable_2");




var button1 = document.querySelector("#btn-Save").addEventListener("click", Addvar);
var button2 = document.querySelector("#btn-show").addEventListener("click", OpenForm);
var button3 = document.querySelector("#btn-calculation").addEventListener("click", Addcal);


function Operation(equation , var1 , var2) {
    switch (equation[1]) {
        case "-": return (Number(var1[0]) - Number(var1[1]))
        case "*": return (Number(var1[0]) * Number(var1[1]))
        case "/": return Number((var1[0]) / Number(var1[1]))
        case "+": return (Number(var1[0]) + Number(var1[1]))
        case "%": return (Number(var1[0]) % Number(var1[1]))
        case "^": return Math.pow(Number(var1[0]) , Number(var1[1]))
        default:text = "Invalid Operation";
    }
}


function Addcal() {
    var rowCount = table2.rows.length;
    var raw = table2.insertRow(rowCount);
   
    raw.insertCell(0).innerHTML = '<input type="text" id = "name2" placeholder=" enter equation" >';
 
    document.getElementById('name2').addEventListener("input",  ()=>{
    let equation = document.getElementById('name2').value;
    console.log(equation, "equation after function");

   console.log("After iteration");

    var var1 = [1];    //for magnitude
    var var2 = [1];   //for unit
   
    console.log(equation, "equation");
    if(equation.length >=3){
$('#table-data tr').each(function (row, tr) {
    if (equation[0] === $(tr).find('td:eq(0)').text()) {

        var1[0] = $(tr).find('td:eq(1)').text();
       
    }
});
$('#table-data tr').each(function (row, tr) {
    if (equation[2] === $(tr).find('td:eq(0)').text()) {
        // console.log(var1[1] , $(tr).find('td:eq(1)').text());

        var1[1] = $(tr).find('td:eq(1)').text();
    }
}
)
console.log(var1);

raw.insertCell(1).innerHTML = Operation(equation, var1 , var2);
//  raw.insertCell(2).innerHTML = 
let btnconvert = document.createElement("button");
let action = raw.insertCell(2);
btnconvert.innerHTML = ("Save");
action.appendChild(btnconvert);

var1 = null;
var2 = null;

return;
}
    
 });

}

json api parse object

Good day, I’m trying to get certain values ​​​​with api the maximum that I can do is output all the json

  const api_url = 'https://api.battlemetrics.com/servers/3753675'
  async function getData() {
    const response = await fetch(api_url);
    const json = await response.json();
    const { data } = json;
    console.log(data)
  }
  getData();

please could tell me how to get the element, I tried like this:

  const api_url = 'https://api.battlemetrics.com/servers/3753675'
  async function getData() {
    const response = await fetch(api_url);
    const json = await response.json();
    const { name, id, status } = json;
    console.log(name, id, status)
  }
  getData();

but i get “undefined undefined undefined”

The object I asked for:

{"data":{"type":"server","id":"3753675","attributes":{"id":"3753675","name":"Rusticated.com Sandbox - Creative | Minigames | Bedwarsr","address":null,"ip":"199.231.233.240","port":28015,"players":201,"maxPlayers":1000,"rank":1,"location":[-87.618889,41.875744],"status":"online","details":{"official":false,"rust_type":"modded","map":"BuildBattleArenaScrimGames","environment":"w","rust_ent_cnt_i":0,"rust_fps":43680,"rust_fps_avg":43680,"rust_gc_cl":null,"rust_gc_mb":null,"rust_hash":"","rust_headerimage":"https://cdn.discordapp.com/attachments/811789078105554984/832668733184671754/Rusticated_Mini_Games_Banner_512x256.png","rust_mem_pv":null,"rust_mem_ws":null,"pve":false,"rust_uptime":null,"rust_url":"https://rustminigames.com","rust_world_seed":1337,"rust_world_size":null,"rust_description":"Rusticated Minigames Beta n Bedwars n Creative n GunGame n Targets n More Coming Soon...","rust_modded":true,"rust_queued_players":0,"rust_born":"2022-06-05T00:00:00.000Z","rust_last_ent_drop":"2021-08-06T00:10:18.261Z","rust_last_seed_change":"2020-09-03T18:33:52.047Z","rust_last_wipe":"2021-08-06T00:10:18.261Z","rust_last_wipe_ent":29035,"serverSteamId":"90159726978107400"},"private":false,"createdAt":"2019-06-18T18:35:26.890Z","updatedAt":"2022-06-06T10:05:57.516Z","portQuery":28038,"country":"US","queryStatus":"valid"},"relationships":{"game":{"data":{"type":"game","id":"rust"}}}},"included":[]}

Infinitescrolling, how to restore state on browser back (items + scrollposition)

Considering this general use case for infinitescrolling:

  1. The infinitescroll has been scrolled and contains e.g. 100-1000 items
  2. One item from the list is selected and the browser routes to a detail page
  3. The user navigates back using the browser back button.
  4. The infinitescroll should show the previous items and be scrolled to the previous location in the list.

Since the use of infinitescrolling is quite common I was hoping to find an out of the box solution that covers this case but I haven’t found a good solution. I did some experiments with localstorage but it get’s a bit tricky with maximum storage when dealing with many complex items from multiple infinitescrolling routes.

What would be a recommended solution or any ideas how to restore the state of the infinitescroll upon browser back?

submit button is not working in simple html form – python flask server

My Submit Button in HTML/CSS/JS is not working.
Here I attached HTML code
However, I tested my flask server in postman but in simple HTML form submit button is not working!

is it something that is I missed in HTML or in JS ?
Please help me with this problem.

<!DOCTYPE html>
    <html>
    <head>
        <title>Banglore Home Price Prediction</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script src="app.js"></script>
        <link rel="stylesheet" href="app.css">
    </head>
    <body>
    <div class="img"></div>
    <form class="form">
        <h2>Area (Square Feet)</h2>
        <input class="area"  type="text" id="uiSqft" class="floatLabel" name="Squareft" value="1000">
        <h2>BHK</h2>
        <div class="switch-field">
            <input type="radio" id="radio-bhk-1" name="uiBHK" value="1"/>
            <label for="radio-bhk-1">1</label>
            <input type="radio" id="radio-bhk-2" name="uiBHK" value="2" checked/>
            <label for="radio-bhk-2">2</label>
            <input type="radio" id="radio-bhk-3" name="uiBHK" value="3"/>
            <label for="radio-bhk-3">3</label>
            <input type="radio" id="radio-bhk-4" name="uiBHK" value="4"/>
            <label for="radio-bhk-4">4</label>
            <input type="radio" id="radio-bhk-5" name="uiBHK" value="5"/>
            <label for="radio-bhk-5">5</label>
        </div>
    </form>
    <form class="form">
        <h2>Bath</h2>
        <div class="switch-field">
            <input type="radio" id="radio-bath-1" name="uiBathrooms" value="1"/>
            <label for="radio-bath-1">1</label>
            <input type="radio" id="radio-bath-2" name="uiBathrooms" value="2" checked/>
            <label for="radio-bath-2">2</label>
            <input type="radio" id="radio-bath-3" name="uiBathrooms" value="3"/>
            <label for="radio-bath-3">3</label>
            <input type="radio" id="radio-bath-4" name="uiBathrooms" value="4"/>
            <label for="radio-bath-4">4</label>
            <input type="radio" id="radio-bath-5" name="uiBathrooms" value="5"/>
            <label for="radio-bath-5">5</label>
        </div>
            <h2>Location</h2>
        <div>
      <select class="location" name="" id="uiLocations">
        <option value="" disabled="disabled" selected="selected">Choose a Location</option>
            <option>Electronic City</option>
            <option>Rajaji Nagar</option>
      </select>
    </div>
        <button class="submit" onclick="onClickedEstimatePrice()" type="button">Estimate Price</button>
        <div 
            id="uiEstimatedPrice" class="result">   <h2></h2> 
        </div>
    </body>
    </html>

How can i map my dictionnarie (one elment)

I’m working on reactJS and i try to displays informations from my dictionnary, but it doesn’t work.

I already did a loop with “for” but i can’t display it so i tried to do a map function.

There is my code :

const Mails = Object.freeze([
    {
        from: "Ludo",
        to: "Guillaume",
        when: "12:05:2022",
        Subject: "Absence",
        Message: "ptit tube",
        Vu : ''
    },
    {
        from: "Luda",
        to: "Guillaume",
        when: "12:05:2022",
        Subject: "Absence",
        Message: "ptit tube",
        Vu : ''
    },


]);



const test = () => {
    for (var index = 0; index < Mails.length; index++) {
        console.log(Mails[index]["from"])
      //   return(
      //       <h1>Mails[index]["from"] </h1>
      //   )
    }
    return (
     <h1>a</h1>
    );
};

export const Messagerie = () => {

    const obj = [{
        foo: 'bar',
        baz: 42
      }]
      
    
       const list_mails = () => {   
        for (var index = 0; index < Mails.length; index++) {
            console.log(Mails[index]["from"])
          //   return(
          //       <h1>Mails[index]["from"] </h1>
          //   )
        }
       
    };
    
    
   

    return (
        <Layout title="Messagerie" loggedIn={true} accountType={parentCookies.name}>
            <Seo title="Messagerie" />

    
            <div>
                {list_mails()}
            </div>
        </Layout>
    );
};

i want to display ludo, then luda in a map function.
I already tried to do my for loop function in a return but it seems impossible.

i tried to follow this example:

How to map a dictionary in reactJS?

but it prints all the elements. I just want to display (or take) the from

(The console.log in my test function prints the corrects elements but i’m not able to return them).

Thank you for yours answers

Conflicts when using ThemeProvider CSS

I recently had a project with a requirement to support theming on the website. So, I’m building a webSite and I’m using ThemeProvider to style it. I have a main layout where I provide all my css. The problem is when I navigate through pages, my navigation bar and breadcrumbs css change according a specified page like the example below. What could be the problem here?

let theme = createTheme({
  palette: {
    primary: {
      light: '#63ccff',
      main: '#C66262',
      dark: '#006db3',
    },
  },
  typography: {
    h5: {
      fontWeight: 500,
      fontSize: 26,
      letterSpacing: 0.5,
    },
  },
});

theme = {
  ...theme,
  components: {
    
    MuiButton: {
      styleOverrides: {
        root: {
          textTransform: 'none',
        },
        contained: {
          boxShadow: 'none',
          '&:active': {
            boxShadow: 'none',
          },
        },
      },
    },
    MuiIconButton: {
      styleOverrides: {
        root: {
          padding: theme.spacing(1),
        },
      },
    },
    MuiDivider: {
      styleOverrides: {
        root: {
          backgroundColor: 'rgb(255,255,255,0.15)',
        },
      },
    },
    MuiListItemButton: {
      styleOverrides: {
        root: {
          '&.Mui-selected': {
            color: '#4fc3f7',
          }
        },
      },
    },
    MuiListItemText: {
      styleOverrides: {
        primary: {
          color: '#fff',
          fontSize: 14,
          fontWeight: theme.typography.fontWeightMedium,
        },
      },
    },
    MuiListItemIcon: {
      styleOverrides: {
        root: {
          color: '#fff',
          minWidth: 'auto',
          marginLeft: theme.spacing(2),
          '& svg': {
            fontSize: 20,
          },
        },
      },
    },
  },
};

const AppLayout = ({ children, style, title, onClick, bottomNav = false }) => {

  return (
    
    <ThemeProvider theme={theme} >
      <Box sx={{ display: 'flex', minHeight: '100vh' }}>
        <CssBaseline />
        <Box
          component="nav"
          sx={{ width: { sm: drawerWidth }, flexShrink: { sm: 0 } }}
        >
          {isSmUp ? null : (
            <Navigator
              PaperProps={{ style: { width: drawerWidth, backgroundColor:"#081627" } }}
              variant="temporary"
              open={mobileOpen}
              onClose={handleDrawerToggle}
            />
          )}
          <Navigator
            PaperProps={{ style: { width: drawerWidth, backgroundColor:"#081627" } }}
            sx={{ display: { sm: 'block', xs: 'none' } }}
          />
        </Box>
        <Box sx={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
          <Header onDrawerToggle={handleDrawerToggle} />
          <Box component="main" sx={{ flex: 1, py: 6, px: 4, bgcolor: '#eaeff1' }}>
            <Paper>
              {children}
            </Paper>
          </Box>
          <Box component="footer" sx={{ p: 2, bgcolor: '#eaeff1' }}>
            <Copyright />
          </Box>
        </Box>
      </Box>
    </ThemeProvider >
  );
};
export default AppLayout;

enter image description here

enter image description here

Is there a way to run a function if the user of my webpage hits a certain point on it?

I try do a webite with different divs or for me they are sections. If I reached the top of one of these it should console log this term. If u ask, ScrollHeight is equal to 1% of the devices’ screenheight.

let Point1 = false;
document.addEventListener("scroll", e=> {
if (document.documentElement.scrollTop >= 150*ScrollHeight) {
    if (Point1 == false){
        Point1 = true;
        Point1F();
    };
}
})
function Point1F() {
console.log("U've done it');
}

But its not woking for me.

Error javascript : Cannot read properties of null (reading ‘innerHTML’)

I’m just learning javascript, I’m using HTML DOM InnerHTML to display a list of data that I created and my code is based on OOP.

When it’s on the page, it looks good. But when I move to another page, the error appears like this.

enter image description here

How can I get rid of the error. I want to display a list of data with innerHTML on another page but can’t because of this error.
This is my code :

let listCattle = [];

let nCattle = CattleDummy.length;
for (let i=0; i<nCattle; i++){
    s = CattleDummy[i];
    listCattle[i] = new Cattle();
    listCattle[i].addCattle(s._id, s.gender, s.cowType, s.age, s.weight, s.deseaseHistory, s.dateofDesease);    
}

tableCattle(listCattle);

function tableCattle(data){
    let table = document.getElementById('CattleTable')

    for(let i=0; i<data.length; i++){
        let row = `<tr>
                    <td>${data[i].getId()}</td>
                    <td>${data[i].getGender()}</td>
                    <td>${data[i].getSpecies()}</td>
                    <td>${data[i].getAge()}</td>
                    <td>${data[i].getWeight()}</td>
                    <td>${data[i].getDeseaseHist()}</td>
                    <td>${data[i].getHealthy()}</td>
                    <td>${data[i].getCondition()}</td>
                </tr>`
        table.innerHTML += row
    }
}
<div class="container" style="margin-top: 30px;">
        <table class="table">
            <thead>
            <tr>
                <td>ID</td>
                <td>Gender</td>
                <td>Species</td>
                <td>Age</td>
                <td>Weight</td>
                <td>Desease History</td>
                <td>Healthy</td>
                <td>Condition</td>
            </tr>
            </thead>
            <tbody class="table-group-divider" id="CattleTable">
            </tbody>
        </table>
    </div>

React js setstate not working in nested axios post

I am trying to access the res.data.id from a nested axios.post call and assign it to ‘activeId’ variable. I am calling the handleSaveAll() function on a button Click event. When the button is clicked, When I console the ‘res.data.Id’, its returning the value properly, but when I console the ‘activeId’, it’s returning null, which means the ‘res.data.id’ cannot be assigned. Does anyone have a solution? Thanks in advance

const [activeId, setActiveId] = useState(null);

useEffect(() => {}, [activeId]);

const save1 = () => {
      axios.get(api1, getDefaultHeaders())
        .then(() => {
          const data = {item1: item1,};

          axios.post(api2, data, getDefaultHeaders()).then((res) => {
            setActiveId(res.data.id);
            console.log(res.data.id); // result: e.g. 10
          });
      });
};

const save2 = () => {
  console.log(activeId); // result: null
};

const handleSaveAll = () => {
  save1();
  save2();

  console.log(activeId); // result: again its still null
};

return (
  <button type='submit' onClick={handleSaveAll}>Save</button>
);

insert array of array elements in loop

index of two variables in first iteration
0,0
and the result would be

===>first array[0]
===>second array [[0]]

index of two variables in second iteration
0,1
and the result would be

===>first array[0,1]
===>second array [[0,]]

index of two variables in second array index iteration
1,0
and the result would be

===>first array[2]
===>second array [[0,1],[2]]

index of two variables in second array index iteration
2,1
and the result would be

===>first array[2,3]
===>second array [[0,1],[2,3]]

I tried with splice method. But it is updating all the arrays.