I need to get the data stored to my sqlite data.db file and displayed in the table

I got this code from Youtube, it’s very useful, but the data is being stored in a websql database, and I would like it to be stored instead in a database file called data.db located in my data folder. How could I do that process using javascript, or node. Not other technologies.

I would like you to help me to store the data in my sqlite database, I attach an image of my structure in case it is needed. I can only use html, css, js and sqlite in my project.
Structure of my project, (sql.js file is not being used)

HTML

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <link href='http://fonts.googleapis.com/css?family=Bitter:400,700,400italic' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="style.css" />
        <script src="https://code.jquery.com/jquery-3.7.0.min.js" integrity="sha256-2Pmvv0kuTBOenSvLm6bvfBSSHrUJ+3A7x6P5Ebd07/g=" crossorigin="anonymous"></script>
        <script src="https://requirejs.org/docs/release/2.3.6/r.js"></script>
        <script src="main.js"></script>
        <script src="banco.js"></script>
        <script src="sqlite3.js"></script>
        <title>SQLite: Insert, Select & Update</title>
    </head>

    <body>
        <h1>SQLite: Insert, Select & Update</h1>
        <div class="aligncenter">
            <form class="form">
                <input type="hidden" id="field-id" value="" />
                <div class="box">
                    <input type="text" id="field-name"/>
                    <label for="field-name">Nome</label>
                </div>

                <div class="box">
                    <input type="text" id="field-pass"/>
                    <label for="field-pass">Senha</label>
                </div>

                <div class="box">
                    <input type="text" id="field-mail"/>
                    <label for="field-mail">E-mail</label>
                </div>
                <div class="per"><a id="btn-salvar" class="button" >SALVAR</a></div>
                <div class="per"><a id="btn-deletar" class="button" >DELETAR</a></div>
            </form>
            <table id="table-register">
                <thead>
                    <th>Nome</th>
                    <th>Senha</th>
                    <th>Email</th>
                </thead>
                <tbody id="tbody-register">
                
                </tbody>
            </table>
        </div>
    </body>

</html>

#JS with the functions

window.addEventListener('load', carregado);

var db = openDatabase("myDB", "1.0", "TiPS Database Example", 2 * 1024 * 1024);



function carregado(){    
    
    document.getElementById('btn-salvar').addEventListener('click', salvar);
    document.getElementById('btn-deletar').addEventListener('click', deletar);
    
    db.transaction(function(tx) {
        //tx.executeSql("DROP TABLE myTable" );
        tx.executeSql("CREATE TABLE IF NOT EXISTS myTable ( id INTEGER PRIMARY KEY,nome TEXT,senha TEXT, email TEXT)" );
//        tx.executeSql('INSERT INTO myTable ( nome,senha,email) VALUES ("a", "b", "c")');
    });
    
    mostrar();
    
}   

function salvar(){
    var id = document.getElementById('field-id').value;
    var nome = document.getElementById('field-name').value;
    var pass = document.getElementById('field-pass').value;
    var mail = document.getElementById('field-mail').value;

    db.transaction(function(tx) {
        if(id){
            tx.executeSql('UPDATE myTable SET nome=?, senha=?, email=? WHERE id=?', [nome,pass,mail,id],null);
        }else{
            tx.executeSql('INSERT INTO myTable ( nome,senha,email) VALUES (?, ?, ?)', [nome,pass,mail]);
        }
    });

    mostrar();
    limpaCampo();
    inputSHOW(false);
}

function mostrar(){        
    var table = document.getElementById('tbody-register');

    db.transaction(function(tx) {
        tx.executeSql('SELECT * FROM myTable', [], function (tx, resultado) {
            var rows = resultado.rows;
            var tr = '';
            for(var i = 0; i < rows.length; i++){
                    tr += '<tr>';
                    tr += '<td onClick="atualizar(' + rows[i].id + ')">' + rows[i].nome + '</td>';
                    tr += '<td>' + rows[i].senha + '</td>';
                    tr += '<td>' + rows[i].email + '</td>';
                    tr += '</tr>';                   
            }
                table.innerHTML = tr; 

        }, null);
    });
}

function atualizar(_id){   
    
    var id = document.getElementById('field-id');
    var nome = document.getElementById('field-name');
    var pass = document.getElementById('field-pass');
    var mail = document.getElementById('field-mail');
    
    id.value = _id;
    
    db.transaction(function(tx) {
        tx.executeSql('SELECT * FROM myTable WHERE id=?', [_id], function (tx, resultado) {
            var rows = resultado.rows[0];

            nome.value = rows.nome ;
            pass.value = rows.senha ;
            mail.value = rows.email ;
        });
    });
    inputSHOW(true);
}

function deletar(){
    
    var id = document.getElementById('field-id').value;
    
    db.transaction(function(tx) {
        tx.executeSql("DELETE FROM myTable WHERE id=?", [id]);
    });
    
    mostrar();
    limpaCampo();
    inputSHOW(false);
}

This code is not important. But I always attach it
JS

window.addEventListener('load',carrega);

function carrega(){
    document.getElementById('field-name').addEventListener('blur', leave);
    document.getElementById('field-pass').addEventListener('blur', leave);
    document.getElementById('field-mail').addEventListener('blur', leave);   
}
function leave(){
    if(this.value != ''){
        this.offsetParent.className += " ativo";
    }else{
        this.offsetParent.className = 'box';
    }
}

function inputSHOW(_show){
    if(_show){
        document.getElementById('field-name').offsetParent.className += " ativo";
        document.getElementById('field-pass').offsetParent.className += " ativo";
        document.getElementById('field-mail').offsetParent.className += " ativo";
        document.getElementById('btn-deletar').style.display = 'block';
    }else{
        
        document.getElementById('field-name').offsetParent.className = 'box';
        document.getElementById('field-pass').offsetParent.className = 'box';
        document.getElementById('field-mail').offsetParent.className = 'box';
        //document.getElementById('btn-deletar').style.display = 'none';
    }
}

function limpaCampo(){
    
    document.getElementById('field-id').value = '';
    document.getElementById('field-name').value = '';
    document.getElementById('field-pass').value = '';
    document.getElementById('field-mail').value = '';
}

Django static don’t read bootstrap javascripts file

When I import bootstrap css and js to django as static, css file connected and works, but js file show me error: “GET /static/bootstrap/js/bootstrap.min.js HTTP/1.1” 404 179.

My ‘main.html’

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    {% load static %}
    <!-- Bootstrap -->
    <link
      rel="stylesheet"
      href="{% static 'bootstrap/css/bootstrap.min.css' %}"
    />
    <!-- DataTables -->
    <!-- Bootstrap JS -->
    <script src="{% static 'bootstrap/js/bootstrap.min.js' %}" />
    <!-- DataTables JS-->
    <!-- DataTable Scripts -->
  </head>
  <body>
    {% include 'navbar.html' %}
    <main>
      <div class="container">
        {% if messages %} {% for message in messages %}
        <div class="alert alert-{{message.tags}}">{{message}}</div>
        {% endfor %} {% endif %} {% block context %} {% endblock context %}
        <footer class="footer">
          <div class="container">
            <p>© Copyright {% now "Y" %} by <a href=""></a></p>
          </div>
        </footer>
      </div>
    </main>
  </body>
</html>

My ‘setting.py’

STATIC_URL = "static/"
STATICFILES_DIRS = [
    BASE_DIR / "static",
]

My web structures:
enter image description here

I need import css and js files as static, but django don’t see js files, I don’t understand what I’m doing wrong.

delete table row using modal confirmation with javascript

I want to delete row from a table. In the table, I have a column which include the following actions (Update,Delete). When I click the delete button, a confirmation modal pops up. In the confirmation modal, if I click the “Confirm” button which means “delete”, the row keeps showing and did not removed.

// add data into table 
const arr = [{name: 'monica', email: '[email protected]', teamName: 'SED', balance: 500},
            {name: 'John Doe', email: '[email protected]', teamName: 'SWD', balance: 1000},
            {name: 'Jack', email: '[email protected]', teamName: 'SED', balance: 400}]


pushDataToTable(arr);

function pushDataToTable(arr){
    const tbody = document.getElementById('tbody');
    const deleteModalDiv = document.getElementById('deleteModal');
    tbody.innerHTML = "";
    deleteModalDiv.innerHTML = "";
    for(let i = 0; i < arr.length; i++){
        tbody.innerHTML += `<tr>
        <td>${arr[i].name}</td>
        <td>${arr[i].email}</td>
        <td>${arr[i].teamName}</td>
        <td>${arr[i].balance}</td>
        <td><button class="btn update-btn">Update</button><button class="btn delete-btn" data-bs-toggle="modal" data-bs-target="#confirmDeleteModal-${i}">Delete</button></td>
        </tr>`

        deleteModalDiv.innerHTML += `<div class="modal fade" id="confirmDeleteModal-${i}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="staticBackdropLabel">Delete User Confirmation</h5>
              <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
              Are you sure?
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
              <button type="button" class="btn btn-primary">Confirm</button>
            </div>
          </div>
        </div>
      </div>`
    }
}
<!--delete modal-->
<div id="deleteModal"></div>

 <table class="table table-hover table-bordered rounded rounded-6 overflow-hidden">
<thead>
   <tr>
     <th>Name</th>
     <th>Email Address</th>
     <th>Team Name</th>
     <th>Balance</th>
     <th></th>
   </tr>
 </thead>
<tbody id="tbody"></tbody>
</table>

How to delete row from a table after clicking on the confirm button in a modal? I want to solve this problem using javascript. don’t provide jquery solution please.

Suggestion on deploying executable software with react

At the moment, I have a react app that can be hosted at localhost:3000 with “npm start” and it runs without error.
Im just wondering if it’s possible to make it an executable file so that I could use it on other desktops just by installing/downloading.

Thank you for the help.

I tried to research but couldn’t find the right answer I was looking for.

Can other people deploy to my page If I’ve made the GitHub repository public?

I’ve recently deployed a react project from the first time and also made its repository public.
I was wondering if is it possible for other to people fork and then to deploy their changes to my deployed page without my permission just because I’ve made the repository public? This is my first time deploying so sorry if it sounds super silly.

The homepage in the package.json file has the link to my page so if people fork it they will have the same link for it in their package.json file too; but does it mean that if they choose to deploy their version without changing the homepage link, it gets deployed to my page?
My guess is that they probably can’t do that because the link is for my GitHub username only, but I still wanted to ask to be sure.

Thank you in advance!

People can’t commit code to the original repository without me accepting their pull request so I’m not worried about them changing the deployed version through the original repository.

How to reference the `this` attribute of a class method when passed to a function as a callback [duplicate]

I have a class with a method that accesses some instance properties of the class. I am trying to call this method by passing it as a callback to an outside function, but my approach causes the program to crash at runtime because the this attribute is undefined. From what I read, this could be because the function is defining its own this, which is why I made it an arrow function, but that still doesn’t resolve the issue. Here is an approximation of the code:

class Foo {
  bar = 0;

  modifyBar(value) {
    this.bar = value; // TypeError: Cannot set properties of undefined (setting 'bar')
  }

  constructor() {
    call(this.modifyBar);
  }
}

const call = (callback) => {
  // ...
  callback(1);
};

const foo = new Foo();

I have tried using the method.call attribute and passing in the class this attribute, but to me that seems like a hack and unnecessarily verbose. My question is: what’s the reason that this evaluates to undefined at runtime?

This is the code that achieves what I want using method.call:

class Foo {
  bar = 0;

  modifyBar(value) {
    this.bar = value;
  }

  constructor() {
    call(this, this.modifyBar);
  }
}

const call = (instance, callback) => {
  // ...
  callback.call(instance, 1);
};

const foo = new Foo();
console.log(foo.bar); // 1

P.S. I know that the way my logic is setup seems abstract, and that I could simply move call into the class definition, but in my actual application it is more of a utility function that performs various side effects in different contexts. This is why I’m looking for a solution to do it exactly this way.

SwiperJs fade effect

I have a simple slider with SwiperJs, but when I add a fade effect, it still scrolls by default. How can I fix it?

My project uses Laravel Blade, Vite and Swiper 9.4.1 if it matters…

Code:

import Swiper from "swiper";

const options = {
  slidesPerView: 1,
  effect: "fade",
  spaceBetween: 16,
  speed: 300,
  loop: true,
  allowTouchMove: false,
};

const slider_1 = new Swiper("#best-sellers-slider-1", options);
const slider_2 = new Swiper("#best-sellers-slider-2", options);
const slider_3 = new Swiper("#best-sellers-slider-3", options);

const nextButton = document.querySelector("#best-seller-next");
const prevButton = document.querySelector("#best-seller-prev");

nextButton.addEventListener("click", () => {
  slider_1.slideNext();
  slider_2.slideNext();
  slider_3.slideNext();
});

prevButton.addEventListener("click", () => {
  slider_1.slidePrev();
  slider_2.slidePrev();
  slider_3.slidePrev();
});

I’m trying to switch between versions 10.0.4 and 9.4.1. It doesn’t help me fix this error.

Editing One Sheet is Timestamping Another

New to programming so please be patient! I’m using this code to timestamp sheet named “Verify”‘s Col11 based on the first time (only) Col9 is edited. It will be cleared and reset manually, daily.

The issue i’m having is editing Col9 on any sheet makes Col11 on the “Verify” tab timestamped, on the corresponding row that was edited on another sheet. Example, i’ll edit Col9 on “Example Sheet”‘s row 89, and Col11 row 89 on sheet “Verify” is timestamped. I’ll attach the code i’m using below – thank you!

function onEdit(e) {
  var sh = e.source.getSheetByName("Verify");
  var row = e.range.getRow();
  var col = e.range.getColumn();
  var stampCol = sh.getRange(row, 11);
    
  if (col == 9 && !stampCol.getValue()) {
    var tz = e.source.getSpreadsheetTimeZone();
    var date = Utilities.formatDate(new Date(), tz, 'dd-MM-yyyy hh:mm:ss');
    stampCol.setValue(date);
  }
}

File migration : React front > Nextjs back > External API

I can’t seem to make the user’s file to be uploaded to an external API. Everything works fine with Thunderclient.

    async uploadVendorDocument(userId, file) {

        const user = await this.usersModel.findById(userId);

        const data = {
            'id': user.vendor_id,
            'fileName': file.originalname
        }

        //Check session
        const check = await this.checkSession();
        if (!check || (check && check.response_message == 'Error')) {
            // Login to generate a new session
            await this.login();
        }

        const { session_id } = await this.sessionModel.findOne();

        const formData = new FormData();

        formData.append('key', this.configService.get('externalApi.key'));
        formData.append('sessionId', session_id);
        formData.append('file', file);
        formData.append('data', JSON.stringify(data));

        const response = await this.uploadAPI(formData, '/UploadFile.json');

        console.log(response)

        if (response.response_message == 'Success') {

            await this.usersModel.findOneAndUpdate(
                { _id: userId },
                {
                    form_uploaded: true
                },
                {
                    upsert: false,
                    new: true,
                });
        }

        return response

    }



    async uploadAPI(payload, url) {
        try {
            const options = {
                method: 'POST',
                url: url,
                baseURL: this.configService.get('externalApi.api_endpoint'),
                headers: {
                    accept: 'application/json',
                    'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
                },
                data: payload,
            };

            const res = await axios.request(options);
            return res.data;
        } catch (error) {
            console.log('ERR callAPI (EXTERNALAPI): ', error);
            throw error;
        }
    }

When I console.log my file in the back end, this is the result:

{
  fieldname: 'pdfFile',
  originalname: 'sample.pdf',
  encoding: '7bit',
  mimetype: 'application/pdf',
  buffer: <Buffer 25 50 44 46 2d 31 2e 37 0d 25 e2 e3 cf d3 0d 0a 38 38 35 20 30 20 6f 62 6a 0d 3c 3c 2f 4c 69 6e 65 61 72 69 7a 65 64 20 31 2f 4c 20 31 32 30 37 31 39 ... 143557 more bytes>,
  size: 143607
}

The response error states:

ERR callAPI (EXTERNALAPI):  [AxiosError: Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream] {
  code: 'ERR_BAD_REQUEST',...

This is the API documentation page, there is no axios example there : https://developer.bill.com/docs/upload-documents

Some solutions online stated to pass use filepath with fs.createreadstream but I don’t have a filepath.
I tried using Blob also, no luck there.

Thanks for your help!

reset state of other child functional component in react

i have a parent component containing an array and i am mapping to create multiple cards something like this->

const Users = [
    {
      id: 1,
name: "abc",
age: 12,
    },
    {
      id: 2,
name: "def",
age: 22,
    },
    {
      id: 3,
name: "abf",
age: 32,
    },
  ];

{Users.map((h, index) => {
        return (
          <React.Fragment key={index}>
            <User data={h} />
            <br></br>
          </React.Fragment>
        );
      })}

User.js

import { useState } from "react";
import "./style.css";

function User(user) {


  const [copyTxt, setCopyTxt] = useState("Copy");
  const [copyClass, setCopyClass] = useState("button_copy");

  const handleCopy = () => {
    setCopyTxt("Copied!");
    setCopyClass("button_copied");
  };

  return (
    <div className="user_div">
      
        <div className="p-2 flex-fill button_div">
          <button type="submit" onClick={handleCopy} className={copyClass}>
            {copyTxt}
          </button>
        </div>
      </div>

  );
}

export default User;

what i want is lets say if i have 3 copy buttons, for record 1 if i click on button, text should change to Copied.
for record 2 if i click on button, that text should change to Copied but at a time only one button should say copied.
How do i achieve that?

please let me know if any other code needed.

JS. Eventloop. Tasks and microtasks [duplicate]

I have a code.

const result = []

setTimeout(() => result.push(1))

Promise.resolve().then(() => result.push(2))

result.push(3)

new Promise(() => result.push(4)).then(() => result.push(5))

setTimeout(() => console.log(result.toString()), 1000)

why result is [3, 4, 2, 1]?

Where is 5?

I have heard about tasks and microtasks, but don’t understand why 5 not in the array.

Trying to hide irrelevant divs when relevant checkbox is not checked

I have the following code where I have two requirements.

  1. User should be able to check one checkbox. If they check 2nd checkbox, it should uncheck them from the first one.This is working for me based on the JS solution shown in the code below.
  2. Only show checkbox related divs and hide other divs. This isn’t working.

NOTE: For some reason, the select2() isn’t working in the code snippet I’ve included below and hence it’s not showing all the divs that shows up after checking a check box. Hence, I am including a JSFiddle link here, which works fine and shows what I’m referring to. So please refer to the JSFiddle link as well to get the complete picture of my problem.

To address point #2 above, I am wondering if I need to switch to CSS classes to better handle showing divs and hiding divs instead of handling it via jQuery .show() and .hide() methods?

//code to select only one checkbox
let boxes = document.querySelectorAll("input[type=checkbox]");
boxes.forEach(b => b.addEventListener("change", tick));
function tick(e) {
  let state = e.target.checked; // save state of changed checkbox
  boxes.forEach(b => b.checked = false); // clear all checkboxes
  e.target.checked = state; // restore state of changed checkbox
}

//Initialize select2
$("#availableLocations").select2();
$("#newLocation").select2();
$("#destinationLocation").select2();
$("#availableLocations").hide();
$("#forNewLocation").hide();
$("#retireLocationChange").hide();
$("#updateLocationChange").hide();
$("#markAsFullChange").hide();
$("#moveContentsChange").hide();

$("[name='changeLocation']").click(function() {
    if ($(this).is(":checked")) {
        $("#forNewLocation").show();
        $("#availableLocations").show();



    } else {
        $("#forNewLocation").hide();
        $("#availableLocations").hide();
    }
});


$("[name='retireLocation']").click(function() {

    if ($(this).is(":checked")) {
        $("#retireLocationChange").show();
        $("#availableRetireLocations").show();
        $("#availableRetireLocations").select2();
    } else {
        $("#retireLocationChange").hide();
        $("#availableRetireLocations").hide();
    }
});

$("[name='updateLocation']").click(function() {

    if ($(this).is(":checked")) {
        $("#updateLocationChange").show();
        $("#availableUpdateLocations").show();
        $("#availableUpdateLocations").select2();

        //Check if user selects something from the dropdown
        $("#availableUpdateLocations").change(function() {

            let locationVal = $(this).val();



        });


    } else {
        $("#updateLocationChange").hide();
        $("#availableUpdateLocations").hide();
    }
});

//mark as full
$("[name='markAsFull']").click(function() {

    if ($(this).is(":checked")) {
        $("#markAsFullChange").show();
        $("#availableMarkAsFullLocations").show();
        $("#availableMarkAsFullLocations").select2();
    } else {
        $("#markAsFullChange").hide();
        $("#availableMarkAsFullLocations").hide();
    }
});



$("#newLocation").change(function() {

    let selectedVal = $(this).val();
    $("#destinationLocation").empty();



});



/*FOR MOVE CONTENTS  */
$("[name='moveContents']").click(function() {

    console.log("Inside Move Contents");
    if ($(this).is(":checked")) {
        $("#moveContentsChange").show();
        $("#tierOneCheckBoxContents").hide();
        $("#tierTwoCheckBoxContents").hide();
        //For Tier One Selection
        $("[name='tierOneMove']").click(function() {

            if ($(this).is(":checked")) {
                console.log("Tier-I move selected");
                $("#tierOneCheckBoxContents").show();
                $("#availableTopLevelLocations").select2();
                $("#contentsInsidetopLevellocation").select2();
                $("#availableDestinationTopLevelLocations").select2();

                $("#contentsInsidetopLevellocation").empty();

                //User selects from the top level drop down ist
                $("#availableTopLevelLocations").change(function() {
                    let locationVal = $(this).val();
                    console.log(locationVal);
                    $("#contentsInsidetopLevellocation").empty();

                });

            } else {
                $("#tierOneCheckBoxContents").hide();
            }
        });



    } else {
        $("#moveContentsChange").hide();
    }
    //End: Tier One Block

    //Tier II move begins
    $("[name='tierTwoMove']").click(function() {


        if ($(this).is(":checked")) {
            console.log("Tier-II move selected");
            $("#tierTwoCheckBoxContents").show();

            $("#availableTopLevelLocationsforTierTwo").select2();
            $("#contentsInsidetopLevellocationfortiertwo").select2();
            $("#contentsInsidetopLevellocationfortiertwo").empty();
            //For multiselect 
            $("#tierThreeId").select2();
            //$('.multiple-select').multipleSelect()
            $("#availableDestinationLocationsforTierTwo").select2();
            //Empty Tier Two location
            $("#contentsInsidetopLevellocationfortiertwo").empty();
            //Empty Tier III location
            $("#tierThreeId").empty();

            //Tier-I location is selected
            $("#availableTopLevelLocationsforTierTwo").change(function() {
                let locationVal = $(this).val();
                console.log(locationVal);

                $("#contentsInsidetopLevellocationfortiertwo").empty();
                $("#tierThreeId").empty();


            });

            //Tier-II location is selected
            $("#contentsInsidetopLevellocationfortiertwo").change(function() {
                //When Tier II option is selected, popuate Tier III with its contents
                let locationVal = $(this).val();
                console.log(locationVal);


            });

            //Tier-III location is selected


        } else {
            $("#tierTwoCheckBoxContents").hide();
        }
    });




});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet"/>


<form id="BuildingManageLocationForm" action="/buildingManageLocation.htm" method="POST">
   <div class="grid-center">
      <div>
         <label>Select one of the checkboxes:</label>
      </div>
      <div>
         <label><input id="changeLocation1" name="changeLocation" type="checkbox" value="true"><input type="hidden" name="_changeLocation" value="on">Change Location</label>
      </div>
      <div>
         <label><input id="updateLocation1" name="updateLocation" type="checkbox" value="true"><input type="hidden" name="_updateLocation" value="on">Update Location</label>
      </div>
      <div>
         <label><input id="retireLocation1" name="retireLocation" type="checkbox" value="true"><input type="hidden" name="_retireLocation" value="on">Retire</label>
      </div>
      <div>
         <label><input id="markAsFull1" name="markAsFull" type="checkbox" value="true"><input type="hidden" name="_markAsFull" value="on">Mark as full</label>
      </div>
      <div>
         <label><input id="moveContents1" name="moveContents" type="checkbox" value="true"><input type="hidden" name="_moveContents" value="on">Move Contents</label>
      </div>
      
      
      <div id="forNewLocation" style="display: none;">
         <label for="newLocation">Select the location type:</label>
         <select id="newLocation" name="newLocation" data-select2-id="select2-data-newLocation" tabindex="-1" class="select2-hidden-accessible" aria-hidden="true">
            <option value="none" selected="" disabled="" data-select2-id="select2-data-4-6m16" hidden="">--Please Select--</option>
            <!-- <option value="Box">Box</option> -->
            <option value="Freezer">Freezer</option>
            <!-- <option value="BUILDING">BUILDING</option> -->
         </select>
         <span class="select2 select2-container select2-container--default" dir="ltr" data-select2-id="select2-data-3-uqyc" style="width: 246.9px;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-disabled="false" aria-labelledby="select2-newLocation-container" aria-controls="select2-newLocation-container"><span class="select2-selection__rendered" id="select2-newLocation-container" role="textbox" aria-readonly="true" title="--Please Select--">--Please Select--</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
         <div>
            <label class="requiredFieldLabel">Select a current location:</label>
         </div>
         <div>
            <select id="availableLocations" name="availableLocations" data-select2-id="select2-data-availableLocations" tabindex="-1" class="select2-hidden-accessible" aria-hidden="true" style="display: none;">
               <option value="-" data-select2-id="select2-data-2-q76u">--Please Select--</option>
            </select>
            <span class="select2 select2-container select2-container--default" dir="ltr" data-select2-id="select2-data-1-0azc" style="width: 246.9px;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-disabled="false" aria-labelledby="select2-availableLocations-container" aria-controls="select2-availableLocations-container"><span class="select2-selection__rendered" id="select2-availableLocations-container" role="textbox" aria-readonly="true" title="--Please Select--">--Please Select--</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
         </div>
         <div>
            <label class="requiredFieldLabel">Select a destination location:</label>
         </div>
         <div>
            <select id="destinationLocation" name="destinationLocation" data-select2-id="select2-data-destinationLocation" tabindex="-1" class="select2-hidden-accessible" aria-hidden="true">
               <option value="-" data-select2-id="select2-data-6-9y2t">--Please Select--</option>
            </select>
            <span class="select2 select2-container select2-container--default" dir="ltr" data-select2-id="select2-data-5-fkw9" style="width: 271.067px;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-disabled="false" aria-labelledby="select2-destinationLocation-container" aria-controls="select2-destinationLocation-container"><span class="select2-selection__rendered" id="select2-destinationLocation-container" role="textbox" aria-readonly="true" title="--Please Select--">--Please Select--</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
         </div>
      </div>
      <div id="retireLocationChange" style="display: none;">
         <div>
            <label class="requiredFieldLabel">Select a location to retire:</label>
         </div>
         <div>
            <select id="availableRetireLocations" name="availableRetireLocations">
               <option value="-">--Please Select--</option>
               <option value="3">BOX#3</option>
               <option value="6">FREEZER#1</option>
               <option value="8">FREEZER#2</option>
               <option value="19">BOX#9</option>
               <option value="20">QBUILDING</option>
               
            </select>
         </div>
      </div>
      <div id="markAsFullChange" style="display: none;">
         <div>
            <label class="requiredFieldLabel">Select a location to mark as full:</label>
         </div>
         <div>
            <select id="availableMarkAsFullLocations" name="availableMarkAsFullLocations">
               <option value="-">--Please Select--</option>
               <option value="3">BOX#3</option>
               <option value="6">FREEZER#1</option>
               <option value="8">FREEZER#2</option>
               <option value="19">BOX#9</option>
               <option value="20">QBUILDING</option>
               
            </select>
         </div>
      </div>
      <div id="updateLocationChange" style="display: none;">
         <div>
            <label class="requiredFieldLabel">Select a location to update:</label>
         </div>
         <div>
            <select id="availableUpdateLocations" name="availableUpdateLocations">
               <option value="-">--Please Select--</option>
               <option value="3">BOX#3</option>
               <option value="6">FREEZER#1</option>
               <option value="8">FREEZER#2</option>
               <option value="19">BOX#9</option>

            </select>
         </div>
         <div>
            <div><label>Update Name:</label></div>
            <div>
               <input id="updateLocationName" name="updateLocationName" type="text" value="" size="35" maxlength="100">
            </div>
         </div>
         <div>
            <div><label>Update Description:</label></div>
            <div>
               <textarea id="updateLocationDescription" name="updateLocationDescription" rows="2" cols="35"></textarea>
            </div>
         </div>
         <div>
            <div><label>Update Comment:</label></div>
            <div>
               <textarea id="updateLocationComment" name="updateLocationComment" rows="2" cols="35"></textarea>
            </div>
         </div>
         <div>
            <div><label>Update Capacity:</label></div>
            <div>
               <input id="updateCapacity" name="updateCapacity" type="text" value="" size="35" maxlength="100">
            </div>
         </div>
      </div>
      <style>
         select {
         width: 30%;
         }
      </style>
      <!-- <style>
         select {
           width: 100%;
         }
         </style>  -->
      <!--BEGIN: Move Contents   -->
      <div id="moveContentsChange" style="display: none;">
         <div>
            <label>Type of move:</label>
         </div>
         <div>
            <label><input id="tierOneMove1" name="tierOneMove" type="checkbox" value="true"><input type="hidden" name="_tierOneMove" value="on">Move contents within Tier-I locations:</label>
         </div>
         <div>
            <label><input id="tierTwoMove1" name="tierTwoMove" type="checkbox" value="true"><input type="hidden" name="_tierTwoMove" value="on">Move contents within Tier-II locations:</label>
         </div>
         <div id="tierOneCheckBoxContents">
            <div>
               <label>Select Tier-I location:</label>
            </div>
            <div>
               <select id="availableTopLevelLocations" name="availableTopLevelLocations">
                  <option value="-">--Please Select--</option>
                  <option value="20">QBUILDING</option>
                  <option value="21">BUILDING#1</option>
                  <option value="22">BUILDING#2</option>
               </select>
            </div>
            <div>
               <div><label>Select Tier-II location:</label></div>
               <div>
                  <select id="contentsInsidetopLevellocation" name="contentsInsidetopLevellocation">
                     <option value="-">--Please Select--</option>
                  </select>
               </div>
            </div>
            <div>
               <label>Select destination location:</label>
            </div>
            <div>
               <select id="availableDestinationTopLevelLocations" name="availableDestinationTopLevelLocations">
                  <option value="-">--Please Select--</option>
                  <option value="20">QBUILDING</option>
                  <option value="21">BUILDING#1</option>
                  <option value="22">BUILDING#2</option>
               </select>
            </div>
         </div>
         <div id="tierTwoCheckBoxContents">
            <div>
               <label>Select Tier-I location:</label>
            </div>
            <div>
               <select id="availableTopLevelLocationsforTierTwo" name="availableTopLevelLocationsforTierTwo">
                  <option value="-">--Please Select--</option>
                  <option value="20">QBUILDING</option>
                  <option value="21">BUILDING#1</option>
                  <option value="22">BUILDING#2</option>
               </select>
            </div>
            <div>
               <div><label>Select Tier-II location:</label></div>
               <div>
                  <select id="contentsInsidetopLevellocationfortiertwo" name="contentsInsidetopLevellocationfortiertwo">
                  </select>
               </div>
            </div>
            <div>
               <div><label>Select Tier-III location:</label></div>
               <div>
                  <select id="tierThreeId" name="tierThreeId" multiple="multiple">
                     <option value="-">--Please Select--</option>
                  </select>
                  <input type="hidden" name="_tierThreeId" value="1">
               </div>
            </div>
            <div>
               <label>Select destination location:</label>
            </div>
            <div>
               <select id="availableDestinationLocationsforTierTwo" name="availableDestinationLocationsforTierTwo">
                  <option value="-">--Please Select--</option>
               </select>
            </div>
         </div>
         <!--END: Move Contents   -->
      </div>
      <div>
      </div>
      <div class="buildingManageLocationButton">
         <button onclick="BuildingManageLocation(); return false">Save
         Your Changes</button>
      </div>
      <div>
         <span id="updateMessage" class="error"></span>
      </div>
   </div>
</form>

how to update the same id field using .innerHTML += method?

In the requirement i need to show some ascending response while user first land into the page and there is a dropdown with option having ascending and descending so when user clicks on desceding it will update the page to descending order and if user click on ascending it will show the ascending response .

Issue -: I have already created and fetched the api for fisrt time when user land now if user click on descending option it’s adding the responses with existing responses and so on click of ascending option .

Link – https://codesandbox.io/s/javascript-forked-gzfsmv?file=/src/index.js

I have already created the code and shows the fecthed response what user need to see while landing on the page . right now i am expecting to show to the user descending response and also if user click on ascending they can see the ascending order .

Why are my values always ‘undefined’ when sending data to render from main in ElectronJS?

So I’m new to electron, still getting a hang of the IPC communication. I’m able to send and receive messages totally fine over IPC (meaning I can confirm in both directions the send and recieve statements are firing). When I send a value from renderer to main, the value comes across totally fine and can be printed out normally. What I don’t understand is why when I try to send a value from main to renderer, no matter what the value will always come through as ‘undefined’. The send and receive statements are still firing, it’s just the value that will not come across properly.

Here I send from renderer to main:

const dataSend = "Test Data" ipcRenderer.send('tester:send', { dataSend });

Here in main I receive that signal, print out (successfully) the data that was sent with it, and then send a new value over a new signal back to the renderer:

`ipcMain.on(‘tester:send’, (e, options) => {
console.log(options.dataSend);

const newData = "The Final Data";
mainWindow.webContents.send('tester:toRender', {
    newData
});

});`

Which is recieved in the renderer here:

ipcRenderer.on('tester:toRender', (e, options) => { console.log("YUP IT ARRIVED"); console.log(options.newData); })

The console.log still fires properly, but no matter what the data type or value, it will always come across as undefined. I’m so stuck I don’t understand, any help would be awesome.

I simply want a way to send a message from renderer to main to access some data, package that data up in main and send it back to renderer to use for visible html elements. I can’t figure out why I can send the message from main to renderer just fine and the receive code will execute, but the data is lost along the way.

Electron not running preload script

I’m new to Electron and going through the Quick Start tutorial, and I’m trying to run the preload script that shows the dependecy versions for Chrome, Node, and Electron. For some reason the preload script is not running. I even added a console log to display when the DOM is loaded, and it never shows in the terminal.

preload.js

window.addEventListener("DOMContentLoaded", () => {
  const replaceText = (selector, text) => {
    const element = document.querySelector(selector);
    if (element) element.innerText = text;
  };

  for (const dependency of ["chrome", "node", "electron"]) {
    replaceText(`${dependency}-version`, process.versions[dependency]);
  }

  console.log("LOADED!");
});

main.js

const path = require("path");
const { app, BrowserWindow } = require("electron");

const createWindow = () => {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
    },
  });

  win.loadFile("index.html");
};

app.whenReady().then(() => {
  createWindow();

  app.on("activate", () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow();
  });
});

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});