How to make only table content scrollable, while keeping everything else inside the div stationery?

I am using HTML, CSS, and JS to create a page to display my CSV data neatly. The table being used to display the CSV data is inside a flexbox container div. Currently, the max height of the container is set to 95vh, and once the table starts the exceeds the height, it makes the entire div container scrollable.

However, I am only looking to make the table data itself scrollable (i.e. <tbody>), not the entire container. This effectively means I want to keep my <h2> header and <thead> header, inside the <div> container, stationery while making the table scrollable if it exceeds the max height of the container.

I have looked at several past SO posts to make only the table content scrollable, and attempted CSS methods such as display: block and position: sticky, but it does not achieve the desired effect I intend for.

If there is a duplicate post to mine (that exactly solves my issue), please link me to it, as I have extensively searched for duplicates. And I would like to solve this issue using pure HTML/CSS/JS or with the help of external scripts.

MY CODE (you can also tinker with my JSFiddle)

// Define CSV data here
const testData = `Value1A,Value1B,Value1C
Value2A,Value2B,Value2C
Value3A,Value3B,Value3C
Value4A,Value4B,Value4C
Value5A,Value5B,Value5C
Value6A,Value6B,Value6C
Value7A,Value7B,Value7C
Value8A,Value8B,Value8C
Value9A,Value9B,Value9C
Value10A,Value10B,Value10C
Value11A,Value11B,Value11C
Value12A,Value12B,Value12C
Value13A,Value13B,Value13C
Value14A,Value14B,Value14C
Value15A,Value15B,Value15C`;

// Split the CSV data
let rows = testData.split("n");

// Add table tags to each row and cell
let table = "";
rows.forEach(function(row) {
  const columns = row.split(/,(?=(?:[^"]*"[^"]*")*(?![^"]*"))/);
  table += `<tr>`;

  // Iterate over each column
  columns.forEach(function(column) {
    table += "<td>" + column.replace(/^"(.*)"$/, "$1") + "</td>";
  });

  table += "</tr>";
});

// Update the table body
const tbody = document.querySelector("#csv-table tbody");
tbody.innerHTML = table;
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
  background-color: #F3F2F1;
  background-color: #d9efa1;
}

.container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 1024px;
  margin: 0 auto;
  padding: 5%;
}

.csv {
  background-color: #FFFFFF;
  border-radius: 10px;
  padding: 3%;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
  max-height: 95vh;
  overflow: auto;
}

.csv h2 {
  margin-top: 1%;
  margin-bottom: 3%;
  margin-left: 0.1%;
  color: #f6b40e;
}

.csv table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.csv table thead th {
  background-color: #f6b40e;
  color: #FFFFFF;
  padding: 3%;
  text-align: left;
}

.csv table tbody tr:nth-child(even) {
  background-color: #F3F2F1;
}

.csv table tbody td {
  padding: 3%;
  word-wrap: break-word;
}
<!DOCTYPE html>
<html>

<head>
  <title>CSV</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>
  <div class="container">
    <div class="csv">
      <h2>CSV</h2>
      <table id="csv-table">
        <thead>
          <tr>
            <th>A</th>
            <th>B</th>
            <th>C</th>
          </tr>
        </thead>
        <tbody>
          <!-- Dynamically generated rows will be added here -->
        </tbody>
      </table>
    </div>
  </div>
</body>

</html>

Hide mapbox and planet (or other tilemap) API from the frontend

I’m trying to hide the access token/api key from the client side. I’m using svelte (not sveltekit) with dotenv to store my keys.

.env

MAPBOX=someaccesstokenkeys
PLANET=someaccesstokenkeys
STYLE=stylefolder/styleid

The map worked just fine, no error. But when I check the source from the element inspector, the keys are still not hidden.

enter image description here

enter image description here

Are there any alternatives? or I have to redo this in sveltekit?

What is the easiest and quickest way to make a website responsive?

kindly tell me, how to make a responsive website in easiest and quickest way. Thanks!

I need a comprehensive answer? —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————- I’m waiting for the answer anxiously

Error: SQLITE_ERROR: near “1123240801246384179”: syntax error

const sub = interaction.options.getSubcommand(["add", "check", "remove", "clear"]);
    const target = interaction.options.getUser('user', true);
    const reason = interaction.options.getString('reason', false) || "No reason provided";
    const evidence = interaction.options.getString('evidence', false) || "No evidence provided";
    const warnid = Number(interaction.options.getString('id')) - 1 || "a";
    const warndate = new Date(interaction.createdTimestamp).toLocaleDateString();
    const usertag = `${target.username}#${target.discriminator}`;
    const embed = new EmbedBuilder();
    const guildId = interaction.guild.id;
    if (!db) {return await interaction.reply('Database connection failed.')}
    if (target.bot === true) {return await interaction.reply(`${target} is a bot, bots can't have warns!`)}
    switch (sub) {
        case "add":
            db.run(`CREATE TABLE IF NOT EXISTS ${String(target.id)} (
                warnid INTEGER NOT NULL PRIMARY KEY UNIQUE AUTOINCREMENT,
                reason TEXT,
                evidence TEXT,
                warndate TEXT NOT NULL,
                tag TEXT NOT NULL,
                guildid TEXT NOT NULL
            )`);
            db.run(`INSERT INTO ${target.id} IF EXISTS (reason, evidence, warndate, tag, guildid)
            VALUES (${reason}, ${evidence}, ${warndate}, ${usertag}, ${(String(interaction.guild.id))}`);
            embed.setTitle(`Warning added to ${target} | ||${target.id}||`)
                .setDescription(`Warned by ${interaction.user}`)
                .setFields(
                    { name: "**Reason**", value: `${reason}` },
                    { name: "**Evidence**", value: `${evidence}` },
                    { name: "**Date warned**", value: `${warndate}` }
                )
                .setColor('Random')
                .setThumbnail(target.displayAvatarURL())
                .setTimestamp();
            await interaction.reply({ embeds:  })
            break

i am trying to store the warnings in a database but got this error:

Error: SQLITE_ERROR: near “1123240801246384179”: syntax error
Emitted ‘error’ event on Statement instance at:
] {
errno: 1,
code: ‘SQLITE_ERROR’
}

Node.js v18.15.0

Cannot set properties of undefined (setting ‘validationData’) when trying to authenticate a user against amazon cognito in react js

I wouldn’t say I’m new to JS but I haven’t stuck with it long enough to be that knowledgeable so hopefully someone here can help. I have recently started making a website with React and I’m getting the following error when attempting to authenticate a user against Amazon Cognito using amazon-cognito-identity-js.
I have looked around but the only thing I can find is from 2016 which is followed by comments saying it was fixed.

Versions:

React:18.2.0
amazon-cognito-identity-js:6.3.1

The error on submit:

Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'validationData')
    at AuthenticationDetails (AuthenticationDetails.js:22:1)
    at cognito.js:11:1
    ...

The aws library code that is causing the error is as follows:

AWS Cognito library (amazon-cognito-identity-js) AuthenticationDetails.js

/**
   * Constructs a new AuthenticationDetails object
   * @param {object=} data Creation options.
   * @param {string} data.Username User being authenticated.
   * @param {string} data.Password Plain-text password to authenticate with.
   * @param {(AttributeArg[])?} data.ValidationData Application extra metadata.
   * @param {(AttributeArg[])?} data.AuthParamaters Authentication paramaters for custom auth.
   */
  function AuthenticationDetails(data) {
    var _ref = data || {},
      ValidationData = _ref.ValidationData,
      Username = _ref.Username,
      Password = _ref.Password,
      AuthParameters = _ref.AuthParameters,
      ClientMetadata = _ref.ClientMetadata;
    this.validationData = ValidationData || {};
    this.authParameters = AuthParameters || {};
    this.clientMetadata = ClientMetadata || {};
    this.username = Username;
    this.password = Password;
  }

I have moved the lines about in debug to see what it does and it happens on any of the lines that seem optional (ending in || {}) even when I explicitly set the values to {}.

My Code

import { CognitoUserPool, CognitoUser, AuthenticationDetails } from 'amazon-cognito-identity-js';
import { cognitoConfig } from './cognitoConfig.js'

const userPool = new CognitoUserPool({
    UserPoolId: cognitoConfig.UserPoolId,
    ClientId: cognitoConfig.ClientId
});

export const signIn = async (username, password) => {
    return new Promise((resolve, reject) => {
        const authDetails = AuthenticationDetails({
            Username: username,
            Password: password
        })
        const cognitoUser = CognitoUser({
            Username: username,
            Pool: userPool
        });

        cognitoUser.authenticateUser(authDetails, {
            onSuccess: (result) => {
                resolve(result);
            },
            onFailure: (err) => {
                reject(err);
            }
        });
    });
};

How can we build a nested responsive nav menu, allowing users to add submenus without more CSS code?

I designed a responsive navigation menu in SASS that allows me to add sub-menus, but each sub-menu requires the creation of a new selector in SASS. I want to style the menu and sub-menus once so that a beginner user does not need to add any new selectors in SASS to add submenus in HTML.

SASS:

@font-face {
    font-family: "Roboto";
    font-style: normal;
    src: url("../Fonts/Roboto.ttf") format("truetype");
}

* {
    font-family: "Roboto";
    font-size: 20px;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    direction: rtl;
}

.logo {
    z-index: 10;
    position: relative;
}

.header {
    float: center;
    background: linear-gradient(to top, #9472ff 2%, #3d00ff 98%) center/100%;
    border-radius: 10px;
    box-shadow: 1px 2px 4px #000000;
    color: white;
    width: 100%;
    height: 100px;
    padding-left: 0px;
    padding-right: 10px;
    padding-top: 40px;
    text-align: right;
    text-shadow: 0px 2px 2px #000000;
}

.nav {
    list-style: none;
    display: flex;
    gap: 24px;
}

.nav li a {
    text-decoration: none;
    font-size: 28px;
    color: #f3b238;
    display: inline-block;
    width: 100%;
    position: relative;
}

.nav li a:hover {
    color: #fff;
}

.nav li a::after {
    content: "";
    width: 0%;
    height: 4px;
    background-color: #fff;
    position: absolute;
    left: 0px;
    bottom: -5px;
    border-radius: 5px;
    transition: all 0.7s ease;
}

.nav li a:hover::after {
    width: 100%;
}

@media (max-width: 769px) {
    .nav {
        position: fixed;
        inset: 0;
        background: linear-gradient(to top, #9472ff 2%, #3d00ff 98%) center/100%;
        flex-direction: column;
        align-items: center;
        padding-top: 150px;
        transform: translateX(100%);
        transition: all 0.7s ease;
    }

    .nav[data-visible=true] {
        transform: translateX(0%);
    }

    .nav-menu-button {
        position: absolute;
        display: flex;
        z-index: 10;
        justify-content: center;
        align-items: center;
        height: 80px;
        width: 80px;
        right: -10px;
        top: -10px;
        cursor: pointer;
        transition: all 0.7s ease-in-out;
    }

    .nav-menu-line {
        width: 50px;
        height: 6px;
        background-color: #d0fd66;
        border-radius: 5px;
        transition: all 0.7s ease-in-out;
    }

    .nav-menu-line::before,
    .nav-menu-line::after {
        content: "";
        position: absolute;
        width: 50px;
        height: 6px;
        background-color: #d0fd66;
        border-radius: 5px;
        transition: all 0.7s ease-in-out;
    }

    .nav-menu-line::before {
        transform: translateY(-16px);
    }

    .nav-menu-line::after {
        transform: translateY(16px);
    }

    .nav-menu-button.open .nav-menu-line {
        transform: translateX(-50px);
        background: transparent;
    }

    .nav-menu-button.open .nav-menu-line::before {
        transform: rotate(45deg) translate(35px, -35px);
    }

    .nav-menu-button.open .nav-menu-line::after {
        transform: rotate(-45deg) translate(35px, 35px);
    }
}

JavaScript:

const MenuButton = document.querySelector(".nav-menu-button");
const Navigation = document.querySelector(".nav");
let MenuOpen = false;
MenuButton.addEventListener("click", () => {
    switch (!MenuOpen) {
        case true:
            MenuButton.classList.add("open");
            Navigation.setAttribute("data-visible", "true")
            MenuOpen = true;
            break;
        default:
            MenuButton.classList.remove("open");
            Navigation.setAttribute("data-visible", "false")
            MenuOpen = false;
            break;
    }
});

HTML:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Pasha-Piano</title>
    <link rel="stylesheet" href="SCSS/AppStyle.css">
    <link rel="stylesheet" href="SCSS/AppStyle.scss" media="(max-width:769px)">
    <link rel="stylesheet" href="Script.js">
</head>

<body>
    <div class="logo" role="img">
        <img src="Images/Logo.png" height="100" style="width:auto; float:left;" />
    </div>
    <header class="header">
        <div class="nav-menu-button">
            <div class="nav-menu-line"></div>
        </div>
        <nav class="nav" data-visible="false" role="navigation">
            <li><a href="#">Home</a></li>
            <li><a href="#">Goods</a></li>
        </nav>
    </header>
    <script src="Script.js"></script>
</body>

</html>

If your answer solves my problem (by using this multi-level dropdown style), I will accept and score it.
Please respond to my question by using Code Snippet.

How to get the number of sender in web whatsapp JS

I want to get the number of new sender and save it in a text file. Is this possible to achieve? any help would be appreciated. Thanks


if (!(sender in userInfo)) {
    console.log("This is a new user.");

    // Create a text file and write the sender number to it
    fs.writeFile('new_users.txt', sender, (err) => {
        if (err) throw err;
        console.log('Sender number added to new_users.txt');
    });

    client.sendMessage(sender, greetings, { mentions: [contact] });
    
    userInfo[sender] = {
        "mode": "mode 1",
        "currentStage": "begin",
        "voice_id": "base",
        "elevenLabsLatency": 3,
    };
    
    return;
}

Erorr when trying to deal with api in React

I’m learning React right now and stuck in the Fetching data from API module. when i try to fetch the api i get the error
(https://i.stack.imgur.com/i6Wfu.png)

and this is the block code

import React from "react";
// import Axios from "axios";
import "./App.css";
import { Axios } from "axios";

function App() {
    fetch("https://catfact.ninja/fact")
        .then((responde) => responde.json())
        .then((data) => {
            console.log(data);
        });
    // Axios.get("https://catfact.ninja/fact").then((res) => console.log(res));

    return <div className="App"></div>;
}

export default App;

Considering:

  • I’m using Firefox v110.0
  • Running Pop_Os (an UBUNTU Des)

I tried to google this error but i got no result.also i tried to update the browser and restart the react app

Google search console shows the wrong Meta Title and Meta Description of my site

This is my domain url https://pearlresidencia.com.pk/ of my site. when i search my site name on google it show the wrong Meta Title and Meta Description. Here is the Screenshot’s have a look at that.

enter image description here

This is the screenshot of my site Meta Title and Meta Description. Im using the plugin AIOSEO for SEO. The Meta Title of all other pages are fine only the issue im facing is in home page.

**Here is the screenshot after the issue
**

enter image description here

Trying to fix this meta title and description on google search

Class is applied but not automatically updated on the HTML page

I am trying to apply a green background to an input box when a form is submitted. The code checks if the letter in the input field is the correct letter and turns the input box green if it is. However, the colour only updates when I type in the correct letter after I pressed the submit button. I want it to turn green when I press submit (not after). I’ve checked the elements in the console and the class green-tile is sucessfully applied however is it not updating the HTML page. Here is my code:

export const compareLetters = (newWord, correctWord, inputArray) => {
  for(let i = 0; i < newWord.length; i++) {
    if(newWord[i] === correctWord[i]) {
      console.log(inputArray);
      inputArray[i].classList.add("green-tile");
      console.log(inputArray[i]);
    } else {
      console.log("This letter does not belong here");
    }
  }
}

Thank you in advance for your responses.

How to fix typescript dynamic type problem

function Middleware<T extends Function>(middleware: Array<{ funcs: Array<keyof T['prototype']>, class: T }>) {

}

class TestValidation {
  Test() { }
}

class FilterValidation {
  Filter() { }
}

I am defining Middleware fonkisyon and I want to use giving class functions as string. But not working.

example usage

Middleware([
    { funcs: ['Test'], class: TestValidation },
    { funcs: ['Filter'], class: FilterValidation}
  ]) 

this code givin error
Type '"Filter"' is not assignable to type 'keyof TestValidation'

how can I fix this problem?

Send a request and re-render the page with the new data in EJS

I have different “name” data sent from server side by EJS, put in <a></a> tags:

<div>
     <% namesArr.forEach(name => { %>
         <a class="other-categories" data-doc="<%= name %>" id="<%= name %>">
            <%= name %>
         </a>
     <% }); %>
</div>

A chosen name would be used inside img.src to display image:
<div><img src="/imgs/<%=selectedName.replace(/s/g,'%20')%>/<%=imgArr[i]%>"></div>

I hope when another “name” is clicked, the page somehow refreshes and re-renders with the specific “name” I click.

I don’t know how to request something from client side to server side, I guess I would need new values such as {newSelectedName, namesArr, imgArr} for below code, since all values come from res.render by Express.js and database using Mongoose model:

Category.find()
.then(result => {
    #getNamesFunction
    #getImgArrFunction
    res.render('index', {selectedName, namesArr, imgArr})
})
.catch(err => console.log(err));

I was thinking to use fetch() and GET method to send a request again, maybe like this:

const otherCategories = document.querySelectorAll('.other-categories');
const endpoint = `/all-categories`;

otherCategories.forEach(category => {
    category.addEventListener('click', function(){
        fetch(endpoint, {
            method: 'GET'
        })
        .then(response => response.json())
        .then(data => #doSomeThing)
        .catch(err => console.log(err))
    })
})

I’m not even sure if this method makes sense, I feel like there is a way to get specific response by different request, so that it might be helpful in my situation.

How can I spoof the request from client to server?

I want to spoof the request from the client so the server accepts the requests.
The server only accepts request from localhost, is it possible to spoof the requests from the client so when the server receives the request headers they contain localhost? I have read that curl or a proxy server might work, but I have not been able to make it work.

I have tried using my public ip but it only works from my wifi, when trying to use the client from another wifi the server rejects the requests.