Merge two objects by join field in javascript

I have project details , which I am getting from two calles, first call contains few fields and another one contains few fields of project details. I have to merge.

projectDetails1

[
  {
    ProjectID: 284,
    ProjectName: "Test Project June-30",
    Budget: 10000,
    BudgetMoney: "10,000.00",
    BriefStatus: "Approved",
    ProjectStatus: "Estimating",
    AID: "B1124-022571-00",
  },
  {
    ProjectID: 285,
    ProjectName: "Test Project June-28",
    Budget: 10000,
    BudgetMoney: "10,000.00",
    BriefStatus: "Approved",
    ProjectStatus: "Estimating",
    AID: "B1124-022571-11",
  },
  {
    ProjectID: 286,
    ProjectName: "Test Project June-28",
    Budget: 10000,
    BudgetMoney: "10,000.00",
    BriefStatus: "Approved",
    ProjectStatus: "Estimating",
    AID: "B1124-022571-22",
  }
]
  

projectDetails2

[
  {
    a_ID: "B1124-022571-00",
    Start_Date: "2022-05-09T00:00:00.000Z",
    End_Date: "2023-05-02T00:00:00.000Z",
    Project_Type_ID: 12,
    Project_Type: "Ext. Delivery (T&M)",
    Active_YN: "Y",
    Committed_Revenue: 3000000,
    Revenue: 4000000,
  },
  {
    a_ID: "B1124-022571-11",
    Start_Date: "2022-04-04T00:00:00.000Z",
    End_Date: "2022-12-30T00:00:00.000Z",
    Project_Type_ID: 12,
    Project_Type: "Ext. Delivery (T&M)",
    Active_YN: "Y",
    Committed_Revenue: 3000000,
    Revenue: 4000000,
  },
]

Need to merge both and by aID and a_ID is common(joining) fields.

finalProjectDeatils:

[
  {
    ProjectID: 284,
    ProjectName: "Test Project June-30",
    Budget: 10000,
    BudgetMoney: "10,000.00",
    BriefStatus: "Approved",
    ProjectStatus: "Estimating",
    AID: "B1124-022571-00",
    Start_Date: "2022-05-09T00:00:00.000Z",
    End_Date: "2023-05-02T00:00:00.000Z",
    Project_Type_ID: 12,
    Project_Type: "Ext. Delivery (T&M)",
    Active_YN: "Y",
    Committed_Revenue: 3000000,
    Revenue: 4000000,
  },
  {
    ProjectID: 285,
    ProjectName: "Test Project June-28",
    Budget: 10000,
    BudgetMoney: "10,000.00",
    BriefStatus: "Approved",
    ProjectStatus: "Estimating",
    AID: "B1124-022571-11",
    Start_Date: "2022-04-04T00:00:00.000Z",
    End_Date: "2022-12-30T00:00:00.000Z",
    Project_Type_ID: 12,
    Project_Type: "Ext. Delivery (T&M)",
    Active_YN: "Y",
    Committed_Revenue: 3000000,
    Revenue: 4000000,
  },
  {
    ProjectID: 286,
    ProjectName: "Test Project June-28",
    Budget: 10000,
    BudgetMoney: "10,000.00",
    BriefStatus: "Approved",
    ProjectStatus: "Estimating",
    AID: "B1124-022571-22",
  }
]

How can I get byte array or stream from html video tag in real time?

I want to use java script to get byte array or realtime stream from html video tags?
I found javascript rendering video to canvas, but not found converting html5 video to array or byte stream.
My idea, convert html5 video to byte array or stream to server from client. I want to use html5 video from webcame or video file.

const processor = {
    timerCallback() {
        if (this.video.paused || this.video.ended) {
            return;
        }
        this.computeFrame();
        setTimeout(() => {
            this.timerCallback();
        }, 16); // roughly 60 frames per second
    },

    doLoad() {
        this.video = document.querySelector("video");
        this.c1 = document.querySelector("canvas");
        this.ctx1 = this.c1.getContext("2d"); 
        this.med =  this.video.captureStream();
        this.video.addEventListener(
            "play",
            () => {
                this.width = this.video.width;
                 this.height = this.video.height; 
                this.timerCallback();
            },
            false
        );
    },

    computeFrame() {
        this.ctx1.drawImage(this.video, 0, 0, this.width, this.height);
        const frame = this.ctx1.getImageData(0, 0, this.width, this.height);
        const l = frame.data.length / 4;

        for (let i = 0; i < l; i++) {
            const grey =
                (frame.data[i * 4 + 0] +
                    frame.data[i * 4 + 1] +
                    frame.data[i * 4 + 2]) /
                3; 
        }
        this.ctx1.putImageData(frame,0,0); 
        return;
    },
};
processor.doLoad();

Problems with the input form

There are three forms, each labeled as tk1, tk2, tk3, and I have an issue with the input form. When I fill them sequentially, starting from tk1, then tk2, and finally tk3, there is no problem. However, if I fill tk1 and then directly fill tk3 without filling tk2, the data sent to the database becomes null, whereas my expectation is that it should be safe even if tk2 is not filled.

Controller

    [HttpPost]
        public ActionResult HasilPengadilan(FormCollection form)
        {
            //updated
            if (Accesses.NeedLogin() == "")
            {
                return RedirectToAction("Index", "Home");
            }

            if (!Accesses.isCreate(idMenu))
            {
                return RedirectToAction("Forbidden", "System");
            }

            int UserId = Convert.ToInt32(Session["UserId"]);

            var submitType = form["submit_type"];

            if (submitType == "tk1")
            {
                var selectedValues = form.GetValues("CourtDecisionCaseId_TK1");
                var selectedIds = new List<string>();
                foreach (var value in selectedValues)
                {
                    selectedIds.Add("'" + value + "'");
                }

                // Membangun query SQL dengan menggunakan parameterized queries dan IN statement
                var query = "SELECT * FROM [Transaction].[Defendants] WHERE DefendantCaseId IN (" + string.Join(",", selectedIds) + ")";
                var defendant = db.Defendants.SqlQuery(query).FirstOrDefault();

                var fname = "CourtDecisionUUID," +
                    "CourtDecisionNumber," +
                    "CourtDecisionDate," +
                    "CourtDecisionProvinces," +
                    "CourtDecisionCities," +
                    "CourtDecisionName," +
                    "CourtDecisionResume," +
                    "CourtDecisionVerdict," +
                    "CourtDecisionDetailVerdict," +
                    "CourtDecisionStatus," +
                    "CourtDecisionCaseId";

                var fvalue = "NEWID()," +
                    "'" + form["CourtDecisionNumber_TK1"] + "', " +
                    "'" + form["CourtDecisionDate_TK1"] + "', " +
                    "'" + form["CourtDecisionProvinces_TK1"] + "', " +
                    "'" + form["CourtDecisionCity_TK1"] + "', " +
                    "'" + form["CourtDecisionName_TK1"] + "', " +
                    "'" + form["CourtDecisionResume_TK1"] + "', " +
                    "'" + form["CourtDecisionVerdict_TK1"] + "', " +
                    "'" + form["CourtDecisionDetailVerdict_TK1"] + "', " +
                    "1," +
                    "'" + form["CaseId_TK1"] + "' ";

                int lastid = db.Database.SqlQuery<int>("INSERT INTO [Transaction].[CourtDecisions] (" + fname + ") VALUES (" + fvalue.Replace("''", "NULL") + "); SELECT CAST(SCOPE_IDENTITY() AS INT) AS LastId;").SingleOrDefault();

                if (lastid == 0)
                {
                    TempData["Notifikasi"] = 2;
                    TempData["NotifikasiText"] = "Data Gagal Disimpan";
                }
                else
                {
                    var decision = db.CourtDecisions.SqlQuery("select * from [Transaction].[CourtDecisions] where CourtDecisionId = " + lastid).FirstOrDefault();

                    var fdefendant = "CourtDecisionDefendantUUID," +
                        "CourtDecisionDefendantDefendantUUID," +
                        "CourtDecisionDefendantDefendantNIK," +
                        "CourtDecisionDefendantStatus," +
                        "CourtDecisionUUID," +
                        "CourtDecisionDefendantCreateBy," +
                        "CourtDecisionDefendantCreateDate";

                    var fdefendantvalue = "NEWID()," +
                        "'" + defendant.DefendantUUID + "', " +
                        "'" + defendant.DefendantNIK + "', " +
                        "'1'," +
                        "'" + decision.CourtDecisionUUID + "', " +
                        "'" + UserId + "', " +
                        "(GETDATE())";

                    int lastiddecision = db.Database.SqlQuery<int>("INSERT INTO [Transaction].[CourtDecisionDefendants] (" + fdefendant + ") VALUES (" + fdefendantvalue.Replace("''", "NULL") + "); SELECT CAST(SCOPE_IDENTITY() AS INT) AS LastId;").SingleOrDefault();

                    if (lastiddecision > 0)
                    {
                        Helpers.Global.InserCaseStatus(form["CaseId_TK1"].ToString(), "PEN17", lastid.ToString(), "Peyidikan/MonitoringPelimpahan/Detail/" + lastid.ToString());
                        TempData["Notifikasi"] = 1;
                        TempData["NotifikasiText"] = "Data Berhasil Disimpan";
                        ViewBag.tk2 = 1;
                        submitType = "tk3";
                    }
                    else
                    {
                        TempData["Notifikasi"] = 2;
                        TempData["NotifikasiText"] = "Data Gagal Disimpan";
                    }
                    return RedirectToAction("Index");
                }
            }
            else if (submitType == "tk2")
            {
                var selectedValues = form.GetValues("CourtDecisionCaseId_Banding");
                var selectedIds = new List<string>();
                foreach (var value in selectedValues)
                {
                    selectedIds.Add("'" + value + "'");
                }

                // Membangun query SQL dengan menggunakan parameterized queries dan IN statement
                var query = "SELECT * FROM [Transaction].[Defendants] WHERE DefendantCaseId IN (" + string.Join(",", selectedIds) + ")";
                var defendant = db.Defendants.SqlQuery(query).FirstOrDefault();

                var fname = "CourtDecisionUUID," +
                    "CourtDecisionNumber," +
                    "CourtDecisionDate," +
                    "CourtDecisionProvinces," +
                    "CourtDecisionCities," +
                    "CourtDecisionName," +
                    "CourtDecisionResume," +
                    "CourtDecisionVerdict," +
                    "CourtDecisionDetailVerdict," +
                    "CourtDecisionStatus," +
                    "CourtDecisionCaseId";

                var fvalue = "NEWID()," +
                    "'" + form["CourtDecisionNumber_Banding"] + "', " +
                    "'" + form["CourtDecisionDate_Banding"] + "', " +
                    "'" + form["CourtDecisionProvinces_Banding"] + "', " +
                    "'" + form["CourtDecisionCity_Banding"] + "', " +
                    "'" + form["CourtDecisionName_Banding"] + "', " +
                    "'" + form["CourtDecisionResume_Banding"] + "', " +
                    "'" + form["CourtDecisionVerdict_Banding"] + "', " +
                    "'" + form["CourtDecisionDetailVerdict_Banding"] + "', " +
                    "2," +
                    "'" + form["CaseId_Banding"] + "' ";

                int lastid = db.Database.SqlQuery<int>("INSERT INTO [Transaction].[CourtDecisions] (" + fname + ") VALUES (" + fvalue.Replace("''", "NULL") + "); SELECT CAST(SCOPE_IDENTITY() AS INT) AS LastId;").SingleOrDefault();

                if (lastid == 0)
                {
                    TempData["Notifikasi"] = 2;
                    TempData["NotifikasiText"] = "Data Gagal Disimpan";
                }
                else
                {
                    var decision = db.CourtDecisions.SqlQuery("select * from [Transaction].[CourtDecisions] where CourtDecisionId = " + lastid).FirstOrDefault();

                    var fdefendant = "CourtDecisionDefendantUUID," +
                        "CourtDecisionDefendantDefendantUUID," +
                        "CourtDecisionDefendantDefendantNIK," +
                        "CourtDecisionDefendantStatus," +
                        "CourtDecisionUUID," +
                        "CourtDecisionDefendantCreateBy," +
                        "CourtDecisionDefendantCreateDate";

                    var fdefendantvalue = "NEWID()," +
                        "'" + defendant.DefendantUUID + "', " +
                        "'" + defendant.DefendantNIK + "', " +
                        "'2'," +
                        "'" + decision.CourtDecisionUUID + "', " +
                        "'" + UserId + "', " +
                        "(GETDATE())";

                    int lastiddecision = db.Database.SqlQuery<int>("INSERT INTO [Transaction].[CourtDecisionDefendants] (" + fdefendant + ") VALUES (" + fdefendantvalue.Replace("''", "NULL") + "); SELECT CAST(SCOPE_IDENTITY() AS INT) AS LastId;").SingleOrDefault();

                    if (lastiddecision > 0)
                    {
                        Helpers.Global.InserCaseStatus(form["CaseId_Banding"].ToString(), "PEN17", lastid.ToString(), "Peyidikan/MonitoringPelimpahan/Detail/" + lastid.ToString());
                        TempData["Notifikasi"] = 1;
                        TempData["NotifikasiText"] = "Data Berhasil Disimpan";
                    }
                    else
                    {
                        TempData["Notifikasi"] = 2;
                        TempData["NotifikasiText"] = "Data Gagal Disimpan";
                    }
                }
                return RedirectToAction("Index");
            }
            else if (submitType == "tk3")
            {
                var selectedValues = form.GetValues("CourtDecisionCaseId_Kasasi");
                var selectedIds = new List<string>();
                foreach (var value in selectedValues)
                {
                    selectedIds.Add("'" + value + "'");
                }

                // Membangun query SQL dengan menggunakan parameterized queries dan IN statement
                var query = "SELECT * FROM [Transaction].[Defendants] WHERE DefendantCaseId IN (" + string.Join(",", selectedIds) + ")";
                var defendant = db.Defendants.SqlQuery(query).FirstOrDefault();

                var fname = "CourtDecisionUUID," +
                    "CourtDecisionNumber," +
                    "CourtDecisionDate," +
                    "CourtDecisionProvinces," +
                    "CourtDecisionCities," +
                    "CourtDecisionName," +
                    "CourtDecisionResume," +
                    "CourtDecisionVerdict," +
                    "CourtDecisionDetailVerdict," +
                    "CourtDecisionStatus," +
                    "CourtDecisionCaseId";

                var fvalue = "NEWID()," +
                    "'" + form["CourtDecisionNumber_Kasasi"] + "', " +
                    "'" + form["CourtDecisionDate_Kasasi"] + "', " +
                    "'" + form["CourtDecisionProvinces_Kasasi"] + "', " +
                    "'" + form["CourtDecisionCity_Kasasi"] + "', " +
                    "'" + form["CourtDecisionName_Kasasi"] + "', " +
                    "'" + form["CourtDecisionResume_Kasasi"] + "', " +
                    "'" + form["CourtDecisionVerdict_Kasasi"] + "', " +
                    "'" + form["CourtDecisionDetailVerdict_Kasasi"] + "', " +
                    "3," +
                    "'" + form["CaseId_Kasasi"] + "' ";

                int lastid = db.Database.SqlQuery<int>("INSERT INTO [Transaction].[CourtDecisions] (" + fname + ") VALUES (" + fvalue.Replace("''", "NULL") + "); SELECT CAST(SCOPE_IDENTITY() AS INT) AS LastId;").SingleOrDefault();

                if (lastid == 0)
                {
                    TempData["Notifikasi"] = 2;
                    TempData["NotifikasiText"] = "Data Gagal Disimpan";
                }
                else
                {
                    var decision = db.CourtDecisions.SqlQuery("select * from [Transaction].[CourtDecisions] where CourtDecisionId = " + lastid).FirstOrDefault();

                    var fdefendant = "CourtDecisionDefendantUUID," +
                        "CourtDecisionDefendantDefendantUUID," +
                        "CourtDecisionDefendantDefendantNIK," +
                        "CourtDecisionDefendantStatus," +
                        "CourtDecisionUUID," +
                        "CourtDecisionDefendantCreateBy," +
                        "CourtDecisionDefendantCreateDate";

                    var fdefendantvalue = "NEWID()," +
                        "'" + defendant.DefendantUUID + "', " +
                        "'" + defendant.DefendantNIK + "', " +
                        "'3'," +
                        "'" + decision.CourtDecisionUUID + "', " +
                        "'" + UserId + "', " +
                        "(GETDATE())";

                    int lastiddecision = db.Database.SqlQuery<int>("INSERT INTO [Transaction].[CourtDecisionDefendants] (" + fdefendant + ") VALUES (" + fdefendantvalue.Replace("''", "NULL") + "); SELECT CAST(SCOPE_IDENTITY() AS INT) AS LastId;").SingleOrDefault();

                    if (lastiddecision > 0)
                    {
                        Helpers.Global.InserCaseStatus(form["CaseId_Kasasi"].ToString(), "PEN17", lastid.ToString(), "Peyidikan/MonitoringPelimpahan/Detail/" + lastid.ToString());
                        TempData["Notifikasi"] = 1;
                        TempData["NotifikasiText"] = "Data Berhasil Disimpan";
                    }
                    else
                    {
                        TempData["Notifikasi"] = 2;
                        TempData["NotifikasiText"] = "Data Gagal Disimpan";
                    }
                    return RedirectToAction("Index");
                }
            }
            else
            {
                TempData["Notifikasi"] = 2;
                TempData["NotifikasiText"] = "Data Gagal Disimpan";
                return RedirectToAction("Index");
            }

            return RedirectToAction("Index");
        }

JavaScript from Views

    if (@tk2 == 1) {
            submit_type = "tk3";
        } else if (@tk1 == 1) {
            submit_type = "tk2";
        } else {
            submit_type = "tk1";
        }

        $("#submit_type").val(submit_type);

File corrupted when using download attribute for a hyperlink?

My company has an internal network to share digital blueprints and documents, but it has problem downloading document by click it and the IT guys are too lazy to fix it so I write a script to help my working experience

Then strange things happens, some files (I didn’t found the clue why some are working while some are not) are corrupted when download by click the hyperlink that I added download attribute for it. If you right click on that file then select save link as..., the downloaded file is ok

Is there any possible reason that the result is different between click link with download and right click on link then save as?

It’s worth noting that those .pdf document has digital signatures (not sure if it’s related)


seudo code of my script

Iterate all <a> element that is not class "dl-added"
if (looks like document link) {
  link.setAttribute("download", "")
  link.classList.add("dl-added)
}

file link element looks like this without my script:

<a href="http://cdn.company-name.com:5000/upload/1234-5678-abcd/name-of-doc%20%A2%BC%D2%E9%78%90.pdf">name</a>

like this with my script:

<a href="http://cdn.company-name.com:5000/upload/1234-5678-abcd/name-of-doc%20%A2%BC%D2%E9%78%90.pdf" download class="dl-added">name</a>


binary content of good pdf file downloaded with right click and save as looks like this

%PDF-1.7..%;sÅx..1 0 obj 
......
startxref..661568..%%EOF.. 

“Corrupted” file looks like this

%PDF-1.7..%;sÅx..1 0 obj 
......
uÛ±1LFIáxw4Ñ#Of²..

When check with HxD, I found that the first ~140kb content of them are exactly the same, but the rest ~490kb is different, all files I tested have similar structure (first xxx kb are good but the rest are bad)

How to get inner value inside a tag? – React Native

I have an array of tags like this:

const tagArray = [<Text>Text1</Text>, <Text>Text2</Text>, <Text>Text3</Text>];

And I want to get the inner value of them this way:

tagArray[0].innerValue; //Output: Text1

I have searched ways to do this but I didn’t find a solution. On web we use innerHTML but obviously that do not work here, how can I do this?

Notice that I do not want to update the value, I just need the inner text.

How to fetch printers and select a specific printer in Expo React Native for Android?

I’m working on a React Native project using Expo, and I need to implement printer selection functionality for Android. In iOS, I’m able to use Print.selectPrinterAsync() to fetch the list of available printers and select a specific printer. However, it seems that this method is only available for iOS and not for Android in Expo.

I have tried using Print.selectPrinterAsync() on Android, but it throws an error indicating that the method is not available.

Is there any alternative or workaround to fetch the list of printers and select a specific printer in Expo React Native for Android? I want to achieve similar functionality as Print.selectPrinterAsync() but for Android.

Here is the code snippet I have tried:

import * as Print from 'expo-print';

const getPrinters = async () => {
  try {
    const printerList = await Print.selectPrinterAsync();
    setAvailablePrinters(printerList);
  } catch (error) {
    console.log('Error fetching printers:', error);
  }
};

I appreciate any guidance or suggestions to resolve this issue.

Fetching full audio file from server

I have a client and server set up. I’m currently fetching the file from my server and then streaming it to the client. I’ve tried to set it up so the audio doesn’t start playing until it’s fully loaded but I still get back partial audio. If I download the file on the browser, however, all of the audio is there. I’m implementing a TTS app so I can’t preload the audio directly. How can I force the browser to not play until the full audio is able to be played through? Here’s what I have so far.

const handleAudioLoaded = () => {
  console.log("Got here for the x'th time");
  const audioElement = document.getElementById(
    "audioplayer"
  ) as HTMLAudioElement;
  if (audioElement) audioElement.play();

{!loading && audio && (
            <ReactAudioPlayer
              id="audioplayer"
              src={`http://localhost:8000/audio/${audio}`}
              onCanPlayThrough={handleAudioLoaded}
              // onLoadedMetadata={handleAudioLoaded}
              preload="auto"
              controls
            />
          )}

Send button on chatbot does not work once clicked

Problem Description:
I am trying to create a chatbot using Python and JavaScript by following a YouTube tutorial. The chatbot user interface (UI) appears correctly, and the button to open the chatbox popup is functioning properly. However, when I enter a message in the input field and click the send button, nothing happens, and the message doesn’t appear in the chatbox. I’m seeking assistance in understanding the reason behind this behavior.

Code:

Here is the code for app.py, responsible for running the application:

from flask import Flask, render_template, request, jsonify
from chat import get_response

app = Flask(__name__)

@app.route("/")
def index():
    return render_template("base.html")

@app.route("/predict", methods=["POST"])
def predict():
    text = request.get_json().get("message")
    # TO-DO: check if text is valid
    response = get_response(text)
    message = {"answer": response}
    return jsonify(message)

if __name__ == "__main__":
    app.run(debug=True, port=5001)

And here is the code for app.js, which contains the chatbot implementation:

class Chatbox {
  constructor() {
    this.args = {
      openButton: document.querySelector(".chatbox__button"),
      sendButton: document.querySelector(".send__button"),
    };

    this.state = false;
    this.messages = [];
  }

  toggleState(chatBox) {
    chatBox.classList.toggle("chatbox--active");
  }

  onSendButton(chatBox) {
    var textField = chatBox.querySelector("input");
    let text1 = textField.value;
    if (text1 === "") {
      return;
    }

    let msg1 = { name: "User", message: text1 };
    this.messages.push(msg1);

    fetch("/predict", {
      method: "POST",
      body: JSON.stringify({ message: text1 }),
      headers: {
        "Content-Type": "application/json",
      },
    })
      .then((r) => r.json())
      .then((r) => {
        let msg2 = { name: "Sam", message: r.answer };
        this.messages.push(msg2);
        this.updateChatText(chatBox);
        textField.value = "";
      })
      .catch((error) => {
        console.error("Error:", error);
        this.updateChatText(chatBox);
        textField.value = "";
      });
  }

  updateChatText(chatBox) {
    var html = "";
    this.messages
      .slice()
      .reverse()
      .forEach(function (item, index) {
        if (item.name === "Sam") {
          html +=
            '<div class="messages__item messages__item--visitor">' +
            item.message +
            "</div>";
        } else {
          html +=
            '<div class="messages__item messages__item--operator">' +
            item.message +
            "</div>";
        }
      });

    const chatMessage = chatBox.querySelector(".chatbox__messages");
    chatMessage.innerHTML = html;
  }

  display() {
    const { openButton, sendButton } = this.args;
    const chatBox = document.querySelector(".chatbox__support");

    openButton.addEventListener("click", () => this.toggleState(chatBox));

    sendButton.addEventListener("click", () => this.onSendButton(chatBox));

    const inputNode = chatBox.querySelector("input");
    inputNode.addEventListener("keyup", (event) => {
      if (event.key === "Enter") {
        this.onSendButton(chatBox);
      }
    });
  }
}

const chatbox = new Chatbox();
chatbox.display();

Furthermore, here is the HTML and CSS code for the chatbot present in base.html:

<!DOCTYPE html>
<html lang="en">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

<head>
    <meta charset="UTF-8">
    <title>Chatbot</title>
</head>
<body>
<div class="container">
    <div class="chatbox">
        <div class="chatbox__support">
            <div class="chatbox__header">
                <div class="chatbox__image--header">
                    <img src="https://img.icons8.com/color/48/000000/circled-user-female-skin-type-5--v1.png" alt="image">
                </div>
                <div class="chatbox__content--header">
                    <h4 class="chatbox__heading--header">Chat support</h4>
                    <p class="chatbox__description--header">Hi. My name is Sam. How can I help you?</p>
                </div>
            </div>
            <div class="chatbox__messages">
                <div></div>
            </div>
            <div class="chatbox__footer">
                <input type="text" placeholder="Write a message...">
                <button class="chatbox__send--footer send__button">Send</button>
            </div>
        </div>
        <div class="chatbox__button">
            <button><img src="{{ url_for('static', filename='images/chatbox-icon.svg') }}" /></button>
        </div>
    </div>
</div>

<script>
    var $SCRIPT_ROOT = "{{ request.script_root|tojson }}";
</script>
<script type="text/javascript" src="{{ url_for('static', filename='app.js') }}"></script>

</body>
</html>

Lastly, the CSS code for styling the chatbot is provided in the style.css file below:

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Nunito", sans-serif;
  font-weight: 400;
  font-size: 100%;
  background: #f1f1f1;
}

*,
html {
  --primaryGradient: linear-gradient(93.12deg, #581b98 0.52%, #9c1de7 100%);
  --secondaryGradient: linear-gradient(
    268.91deg,
    #581b98 -2.14%,
    #9c1de7 99.69%
  );
  --primaryBoxShadow: 0px 10px 15px rgba(0, 0, 0, 0.1);
  --secondaryBoxShadow: 0px -10px 15px rgba(0, 0, 0, 0.1);
  --primary: #581b98;
}

/* CHATBOX
=============== */
.chatbox {
  position: absolute;
  bottom: 30px;
  right: 30px;
}

/* CONTENT IS CLOSE */
.chatbox__support {
  display: flex;
  flex-direction: column;
  background: #eee;
  width: 300px;
  height: 350px;
  z-index: -123456;
  opacity: 0;
  transition: all 0.5s ease-in-out;
}

/* CONTENT ISOPEN */
.chatbox--active {
  transform: translateY(-40px);
  z-index: 123456;
  opacity: 1;
}

/* BUTTON */
.chatbox__button {
  text-align: right;
}

.send__button {
  padding: 6px;
  background: transparent;
  border: none;
  outline: none;
  cursor: pointer;
}

/* HEADER */
.chatbox__header {
  position: sticky;
  top: 0;
  background: orange;
}

/* MESSAGES */
.chatbox__messages {
  margin-top: auto;
  display: flex;
  overflow-y: scroll;
  flex-direction: column-reverse;
}

.messages__item {
  background: orange;
  max-width: 60.6%;
  width: fit-content;
}

.messages__item--operator {
  margin-left: auto;
}

.messages__item--visitor {
  margin-right: auto;
}

/* FOOTER */
.chatbox__footer {
  position: sticky;
  bottom: 0;
}

.chatbox__support {
  background: #f9f9f9;
  height: 450px;
  width: 350px;
  box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.1);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
}

/* HEADER */
.chatbox__header {
  background: var(--primaryGradient);
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  padding: 15px 20px;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: var(--primaryBoxShadow);
}

.chatbox__image--header {
  margin-right: 10px;
}

.chatbox__heading--header {
  font-size: 1.2rem;
  color: white;
}

.chatbox__description--header {
  font-size: 0.9rem;
  color: white;
}

/* Messages */
.chatbox__messages {
  padding: 0 20px;
}

.messages__item {
  margin-top: 10px;
  background: #e0e0e0;
  padding: 8px 12px;
  max-width: 70%;
}

.messages__item--visitor,
.messages__item--typing {
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border-bottom-right-radius: 20px;
}

.messages__item--operator {
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border-bottom-left-radius: 20px;
  background: var(--primary);
  color: white;
}

/* FOOTER */
.chatbox__footer {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px;
  background: var(--secondaryGradient);
  box-shadow: var(--secondaryBoxShadow);
  border-bottom-right-radius: 10px;
  border-bottom-left-radius: 10px;
  margin-top: 20px;
}

.chatbox__footer input {
  width: 80%;
  border: none;
  padding: 10px 10px;
  border-radius: 30px;
  text-align: left;
}

.chatbox__send--footer {
  color: white;
}

.chatbox__button button,
.chatbox__button button:focus,
.chatbox__button button:visited {
  padding: 10px;
  background: white;
  border: none;
  outline: none;
  border-top-left-radius: 50px;
  border-top-right-radius: 50px;
  border-bottom-left-radius: 50px;
  box-shadow: 0px 10px 15px rgba(0, 0, 0, 0.1);
  cursor: pointer;
}

Additional Context:

I have implemented a chatbot based on the tutorial, but when I enter a message and click the send button, nothing happens. I have reviewed the code, and it appears that the onSendButton() function is not being triggered correctly. I expect the message to be sent to the server using the fetch() function and then added to the chatbox messages using the updateChatText() function.

I would appreciate any assistance in identifying why the messages are not displaying after clicking the send button. Thank you!

Why am i getting Cannot read properties of undefined (reading ‘innerHTML’)?

I’m creating a cart for a ecommmerce site I’m in the price of updating the total price of the items correlating to the Quantity but im running an error?

function updatetotal () {
    const cartContent = document.getElementsByClassName("cart-content")[0];
    const cartBoxes = cartContent.getElementsByClassName("cart-box");
    let total = 0;
    for (let i = 0; i < cartBoxes.length;i++) {
        const cartBox = cartBoxes[i];
        const priceElement = cartBox.getElementsByClassName("cart-price")[0];
        const quantityElement = cartBox.getElementsByClassName("cart-quanity");
        let price = parseFloat(priceElement.innerHTML.replace('$',''))
        const quantity = quantityElement.value;
        total+= price * quantity;
        document.getElementsByClassName("total-price")[0].innerText = '$' + total; 

    }
}

I’ve tried just about everything I think its a minor mistake made somewhere maybe?

How to use a JS date functions in React

In the process of learning how React JS works, I have run into statements such as this one:

var StartDate = new Date('2017-12-03T13:32:45.000Z');
  1. I would like to know how I would tell that this is using the JavaScript Date object, instead of an object from somewhere else.

  2. If it is a JavaScript date object are there any imports required for ReactJS to use it?

I would like to automate the task of extracting necessary information such as company names from the Mynavi site and pasting it into the default data

I drive a function within a spreadsheet and made scraping by ImportXML function, but cross a script driving a value into the necessary cell directly so far when ImportXML function is necessary because processing gets heavy when there are too many cells then to open at the time of correction, and to confirm increasing, ImportXML functions.

The which all actually went from scraping in GAS thinks that both the development and the repair are comfortable, but works such because I thought about algorithm to perform scraping in GAS that the which used not having been able to understand oneself, the macro that I have already crossed is early.

When I am going to carry this out, the following error occurs.

don't match the method signature for SpreadsheetApp.Range.copyTo.
The sentence structure that an error is taking place is this.

sheet1.getRange('B' +10 + i). copyTo(Company2, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false),
If there is the one to know including the error of the sentence structure who – is, please tell me.

I drive a function in a seat so that I stick a URL of Mynavi on “a URL pasting up seat” for the rough algorithm of doing it and read the URL by ImportXML function and I extract a necessary place by the function in the seat and cut it off, and the information that is necessary for the appointed form of the spreadsheet comes to the form of the information that I want it after fixing it.

The link of the spreadsheet becomes this.
text`

function myFunction1() {
    var spreadsheet = SpreadsheetApp.getActive();
    //スプレッドシートアプリを開く
    var sheet1 = spreadsheet.setActiveSheet(spreadsheet.getSheetByName('ペースト&作業用シート'), true);
    var sheet2 = spreadsheet.setActiveSheet(spreadsheet.getSheetByName('コピーするシート'), true);
    var sheet3 = spreadsheet.setActiveSheet(spreadsheet.getSheetByName('URL貼り付けシート'), true);
    var sheet4 = spreadsheet.setActiveSheet(spreadsheet.getSheetByName('連絡先等表示シート'), true);  
    //sheet1,2,3,4という名前の箱で、それぞれのシートを入れる(プログラミング的意味の関数)これによって文字数を減らして書くことができる

    for (i=2; i<=11; i++) {
        //For文は、()の条件を満たすまで、{}の内部に書かれた処理を繰り返し実行する
        //これにより、セルを移動しながら終わりの行まで同じ文字列を入れて、値のみをコピーして、消すことを繰り返している
        //var URL1 = sheet3.getRange('A' + i);
        //var URL2 = sheet3.getRange('B' + i);
        //URLを関数に入れる処理を書いておく、まだ使わないが将来的な改修作業の時に役立つ可能性がある、スプレッドシート内でなくGAS内でスクレイピングを行えれば早いが記述が難しいため
        //ここから先の処理は基本的にURL貼り付けシート内の処理をペーストするシートに移す作業
        var Company = sheet3.getRange('D'+ i).getValue();
        if(Company=="")continue;
        Company.replace('正社員既卒', '').getValue();
        Company.replace('(株)', 株式会社).getValue();
        sheet1.getRange('B' + 10 + i).copyTo(Company, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        sheet1.getRange('B' + i - 1).copyTo(Company, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        debugger
            //企業名をCompanyという名前の箱に入れて(プログラミング的意味の関数)、正社員の文字を消し、(株)を株式会社形式に変換する、それを作業用シートに「値をコピー」で貼り付ける
            var Industry = sheet3.getRange('E'+ i + 'F'+ i + 'G'+ i).getValue();
        Industry.replace('業種', '').getValue();
        sheet1.getRange('D' + 10 + i).copyTo(Industry, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        sheet1.getRange('D' + i - 1).copyTo(Industry, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        debugger
            //業種をIndustryという名前の箱に入れて(プログラミング的意味の関数)、業種の文字を消し、それを作業用シートに「値をコピー」で貼り付ける
            var capital = sheet3.getRange('H'+ i).setValue('=IFERROR(CONCATENATE(IMPORTXML(A' + i + ',$C$3)),"")').flush();
        sheet1.getRange('F' + 10 + i).copyTo(capital, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        capital.clear({contentsOnly: true, skipFilteredRows: true});
        debugger
            //資本金を取得する関数をURL貼り付けシートH列に打ち込み、capitalという名前の箱に入れて(プログラミング的意味の関数) それを作業用シートに「値をコピー」で貼り付ける、そしてセルの中身を消す
            var Earnings = sheet3.getRange('I'+ i).setValue('=IFERROR(CONCATENATE(IMPORTXML(A' + i + ',$C$4)),"")').flush();
        sheet1.getRange('H' + 10 + i).copyTo(Earnings, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        Earnings.clear({contentsOnly: true, skipFilteredRows: true});
        debugger
            //売上高を取得する関数を打ち込み、それを作業用シートに「値をコピー」で貼り付ける、そしてセルの中身を消す
            var homepage = sheet3.getRange('N'+ i).setValue('=IFERROR(CONCATENATE(IMPORTXML(A' + i + ',$C$7)),"")').flush();
        sheet1.getRange('H' + 10 + i).copyTo(homepage.getValue(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        homepage.clear({contentsOnly: true, skipFilteredRows: true});
        debugger
            //ホームページを取得する関数を打ち込み、それを作業用シートに「値をコピー」で貼り付ける、そしてセルの中身を消す
            var contact = sheet3.getRange('L'+ i).setValue('=IFERROR(CONCATENATE(IMPORTXML(B' + i + ',$J$3)),"")').flush();
        var mail = sheet3.getRange('M'+ i).setValue('=IFERROR(CONCATENATE(IMPORTXML(B' + i + ',$J$4)),"")').flush();
        var postcode = sheet4.getRange('A'+ i - 1).getValue();
        debugger
            //contactは連絡先情報、postcodeは郵便番号のこと
            //ここから先が連絡先情報セルで行う処理
            var department = sheet4.getRange('G'+ i - 1).getValue();
        var address = sheet4.getRange('B'+ i - 1).getValue();
        //departmenは部署のこと(買い物をするという意味のデパートでは無いです)
        sheet1.getRange('E' + i).copyTo(contact.getValue(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        //コピーするシートのE列に作業用シートの連絡先情報すべてを「値を貼り付け」
        sheet1.getRange('L' + 10 + i).copyTo(postcode.getValue(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        //L列には郵便番号セルに郵便番号を「値を貼り付け」
        sheet1.getRange('N' + 10 + i).copyTo(department, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        //N列に住所を「値を貼り付け」
        sheet1.getRange('P' + 10 + i).copyTo(department, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        //P列に担当部署名を「値を貼り付け」
        var telnum = sheet4.getRange('E' + i - 1);
        sheet1.getRange('R' + 10 + i).copyTo(telnum, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        telnum.clear({contentsOnly: true, skipFilteredRows: true});
        debugger
            //電話番号を取得する関数を打ち込み、それを作業用シートに「値をコピー」で貼り付ける、そしてセルの中身を消す
            var empnum = sheet4.getRange('AE' + i - 1).setValue(Number(empnum)).getValue();
        sheet1.getRange('J' + 10 + i).copyTo(empnum, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
        empnum.clear({contentsOnly: true, skipFilteredRows: true});
        debugger
            //従業員を取得する関数を打ち込み、それを作業用シートに「値をコピー」で貼り付ける、そして数値型にする。
            sheet3.getRange('L'+ i).clear({contentsOnly: true, skipFilteredRows: true});
        //そしてセルの中身を消す
    }
    sheet1.setFontSize(10).setFontFamily(Arial).trim();
    //シート内の文字の大きさと書式を統一し、前後の空白文字を削除する

I revised a sentence structure many times and, in pursuit of a cell and a cord, confirmed it I carried it out, and where an error was taking place. .
I think that how to use, how to write method include misunderstanding, an error of the knowledge
sheet1.getRange('B' +10 + i). copyTo(Company2, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false),
I think that it is certain that an error occurs in this sentence structure

(p5.js) RIGHT doesn’t trigger in function mouseClicked()?

For some reason I can’t enter the condition if (mouseButton === RIGHT).

function mouseClicked()
{
    if (mouseButton === LEFT)
    {
        console.log("left pressed");
        Nodes.push(new Node(mouseX, mouseY));
    }
    else
    {
        console.log("right pressed");
        Attractors.push(new Attractor(mouseX, mouseY));    
    }
}

I tried console.loging for both left and right and swapping the orders of the conditions but only if (mouseButton === LEFT) gets called.

I want to prevent 3 consecutive enter keys in a textarea using javascript

I want two things to happen in the same textarea:

  • the first, I can do: prevent 2 consecutive spaces
  • the second, I need help with: prevent 3 consecutive Enter Keys.

Here is my html code:

onkeypress="return ignoreConsecutiveSpaces(event);"

here is my javascript which I know has problems and even part missin but I just can’t figure it out:

var lastkey4;
var lastkey5;
var lastkey6;
var ignoreChars4 = ' '+String.fromCharCode(0);
var ignoreChars5 = 'rn'+String.fromCharCode(0);
function ignoreConsecutiveSpacesOr3Enter(e) {
    e = e || window.event;
    var char = String.fromCharCode(e.charCode);
    if(ignoreChars4.indexOf(char) >= 0 && ignoreChars4.indexOf(lastkey4) >= 0) {
        lastkey4 = char;
        alert("Do not enter 2 consecutive spaces or enter keys in this form!");
        return false; }
    else {
        lastkey4 = char;
        return true; }
    if(ignoreChars5.indexOf(char) >= 0 && ignoreChars5.indexOf(lastkey5) >= 0 ) {
        lastkey5 = char;
        if(ignoreChars5.indexOf(char) >= 0 && ignoreChars5.indexOf(lastkey5) >= 0 && ignoreChars5.indexOf(lastkey6) >= 0 ) {
        lastkey6 = char;
        alert("Do not enter 3 consecutive enter keys in this form!");
        return false; }
    else {
        return true; }
    
    }

I know I am not gonna be able to do this one on my own, I am gonna need a completed code 🙁 Anyone help? 😛

The lastkey4 -lastkey6 are numbered for a reason, other javascript files.

How to use Anychart and add it to my html code

i cannot add my chart to my html body i use this function

 var data = [
    {name: "Fantasy", value: 637166},
    {name: "Science Fiction", value: 721630,
     normal:   {
               hatchFill: "backward-diagonal",
               stroke: "black"
               },
     hovered:  {
                 fill: "lightGray",
                 hatchFill: "backward-diagonal",
                 stroke: "black"
               },
     selected: {
                 fill: "white",
                 hatchFill: "backward-diagonal",
                 stroke: "black"
               }
    },
    {name: "Detective", value: 148662},
    {name: "Classics", value: 78662},
    {name: "Textbooks", value: 90000}
  ];


  let sed = document.querySelector(".custom")

  sed.appendChild(anychart.pyramid(data).draw);`
and in my body

i create a div with class custom and i add all scripts of anychart and it gives me error what im doing wrong