PDF file sent from flask to client is empty when downloaded

I have a flask server that sends a pdf file with the send_file function.
When I test this route on postman I can view and download the pdf.
However when I try to download it through my React frontend the file is blank BUT with the correct amount of pages.
I suppose the problem stems from my use of blob but I don’t see how.

Server route

@app.route("/test", methods=["GET"])
def results():
    if request.method == "GET":
        return send_file("pdf-path", cache_timeout=0, as_attachment=True)

This route works fine when tested on postman. I can view the pdf

client side

axios.get(URL + '/test')
    .then(function (response) {
        if (response.status === 200) {
            const type = 'application/pdf';
            const file = new Blob([data], { type: type });
            saveAs(file, "test.pdf");
        }
    }
    )

Here I am using axios and file-saver.
The file is downloaded but all the pages are empty.

DiscordJS MessageManager is a circular dependency

I try to get a message by id in discord.js, but returned MessageManager is a circular dependency and I cannot access any of it’s properties.

    console.log(channel.messages)

Shows:

    <ref *2> MessageManager {
        channel: <ref *1> TextChannel {
        type: 'GUILD_TEXT',
        guild: Guild { ... }

And

    channel.messages.fetch(msg_ID)
    .then(msg => {
        console.log(msg)
    })

Shows this, but repeated 50 times:

    'msg_ID' => <ref *50> Message {
        channelId: 'channel_ID',
        guildId: 'guild_ID',
        id: 'msg_ID',
        createdTimestamp: 1652473636758,
        type: 'DEFAULT',

and a bunch of other fields (obviously I changed IDs to 'msg_ID', 'channel_ID' and 'guild_ID', normally it returns proper numbers)

i need hide button befor enter valid data after enter valid data show button .what change is needed?

     ```{{ Form::open(['route' => ['projects.tasks.create', $project_id,$stage_id], 'id' => 'create_task']) }}<div class="row"><div class="col-8"><div class="form-group">
        {{ Form::label('name', __('Task name***'), ['class' => 'form-control-label']) }}
        {{ Form::text('name', null, ['class' => 'form-control', 'required' => 'required' ]) }}
    </div></div><div class="col-12">
    <div class="form-group">
        {{ Form::label('description', __('Description'), ['class' => 'form-control-label']) }}
        <small class="form-text text-muted mb-2 mt-0">{{ __('This textarea will autosize while you type') }}</small>
        {{ Form::textarea('description', null, ['class' => 'form-control', 'rows' => '1', 'data-toggle' => 'autosize']) }}</div></div><div class="col-6"><div class="form-group">
        {{ Form::label('estimated_hrs', __('Estimated Hours***'), ['class' => 'form-control-label']) }}</div></div><div class="col-6"><div class="form-group">
        {{ Form::label('priority', __('Priority'), ['class' => 'form-control-label']) }}
        <small class="form-text text-muted mb-2 mt-0">{{ __('Set Priority of your task') }}</small><select class="form-control" name="priority" id="priority" required>
            @foreach (AppProjectTask::$priority as $key => $val)
                <option value="{{ $key }}">{{ $val }}</option> @endforeach
        </select> </div></div><div class="text-right">

“`
i need hide button before enter valid data and show after enter valid data what i do?

New text not showing up

I made a Quotes generator website, Which uses an API. When I click Generate Quote it is just stuck on loading
How can I fix it?

function randomQuote(){
    quoteBtn.classList.add("loading");
    quoteBtn.innerText = "Loading Quote...";
    fetch("http://api.quotable.io/random").then(response => response.json()).then(result => {
        quoteText.innerText = result.content;
        authorName.innerText = result.author;
        quoteBtn.classList.remove("loading");
        quoteBtn.innerText = "New Quote";
quoteBtn.addEventListener("click", randomQuote);
    });
}

Angular Email Validation through Regex [duplicate]

I am trying to build a regex for email validation in my application but i am not able to get a perfect one :-

I have tried the below regex :-

emailPattern = '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$';

emailPattern1 = '/^(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/';

The above patterns say [email protected] is a valid email. Please help

Had referred link but this too dont work.

Input not clickable native base, image on top

I am using Input from native base with expo app.

I have an input button to select a date via datetimepicker react native library. Upon pressing the input button or as soon as it gains focus , I see the calendar pulled up and can do the required task of selecting date.

However, when I add a icon to display on top of the input element, the input element is clickable only 1 out of 10 times.

Here is my DOM code:

<Input ref={t} value={date.getDate()+"/"+(date.getMonth()+1)+"/"+date.getFullYear()} onChange={onChange}}/> 
 <AntDesign name="calendar" size={22} onPress={t.focus}/>)}

I tried setting focus explicitly with .focus on icon press but that does not work either.

I want to display input with icon embedded inside the input to the right.

javascript setAttribute replacement

I am new to javascript and have problem when play with w3school’s example.
Here is the link the problem from
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_autocomplete

The original sample code for its HTML is

<form autocomplete="off" action="/action_page.php">
  <div class="autocomplete" style="width:300px;">
    <input id="myInput" type="text" name="myCountry" placeholder="Country">
  </div>
  <input type="submit">
</form>

And part of original sample javascript

a = document.createElement("DIV");
a.setAttribute("id", this.id + "autocomplete-list");
a.setAttribute("class", "autocomplete-items");
/*append the DIV element as a child of the autocomplete container:*/
this.parentNode.appendChild(a);
/*for each item in the array...*/
for (i = 0; i < arr.length; i++) {... 

while I replace the HTML to

<form autocomplete="off" action="/action_page.php">
  <div class="autocomplete" style="width:300px;">
    <input id="myInput" type="text" name="myCountry" placeholder="Country">
    <div class="autocomplete-items" style="displey:none"></div>
  </div>
  <input type="submit">
</form>

the style part I actually did it within css style.

and change the javascript to

a = document.querySelector(".autocomplete-items");
a.style.display = "block";

replace the following and keep the rest of the original code.

a = document.createElement("DIV");
a.setAttribute("id", this.id + "autocomplete-list");
a.setAttribute("class", "autocomplete-items");
/*append the DIV element as a child of the autocomplete container:*/
this.parentNode.appendChild(a);

I think the result should be the same but turn out it did not work.
Is there anything wrong with my thought?
I want to skip the createElement part and make it done by html with css display property.

Adding a function to imports routes in app.use()

Hi everyone
I have an API and I have made a function to check if a user is authenticated, if he is then the API redirects him to the home page else to the /login page ,

  1. Authenticate function:

    function checkAuthenticated(req, res, next) {
       if (req.isAuthenticated()) {
            return next()
      }
      res.redirect('/login')
    }
    
  2. Homepage route :

     app.get('/', checkAuthenticated, (req, res) => {
       res.render('index.ejs', { name: req.user.name })
     })
    

But now I want to add this functionality to other routes like the import routes I have made, So can I add the function to the app.use(importRoute)?
Something like this:

app.use('/api/v3/newspapers', checkAuthenticated, v3newspapersRoute);

PS: I’m noob & I’m using ejs for the home/login/register pages and not for the other routes

Youtube video i followed: https://www.youtube.com/watch?v=-RCnNyD0L-s&t=135s

Why I can’t read JavaScript labreries source code

I Need Some tips to learn source code.
for example I want to read nuxt3 source code
but there is many directories and diff files.
My JavaScript knowledge is fine, But I need tips Where can I start read, if there is some course about source code reading or something like that pls Tell me.

Error in getting table row value to be deleted/updated. String input as undefined

I am making a simple CRUD function for a bill management system. It uses Jquery AJAX JSON to communicate to the servlets.

The update and delete functions are activated by buttons in a dynamically generated table with hidden field that contains the ‘billID’.

However when tested it gives an error For input String : “undefined”. I think the error should be in billid hidden field somehow not been set? But I’m not sure and would like a bit of help.

.jsp HTML table.

                <form id="formBill" name="formBill">
                    
                    UserID : <input id="UserID" name="UserID" type="text" class= "form-control form-control-sm" required> <br>
                    
                    Billing Date (yyyy-mm-dd): <input id="BillingDate" name="BillingDate" type="text" class= "form-control form-control-sm" required> <br>
                    
                    Unit Cost : <input id="UnitCost" name="UnitCost" type="text" class="form-control form-control-sm" required> <br>
                    
                    Units Used : <input id="UnitsUsed" name="UnitsUsed" type="text" class="form-control form-control-sm" required> <br>
                    
                    Service Charge : <input id="ServiceCharge" name="ServiceCharge" type="text" class="form-control form-control-sm" required> <br>
                    
                    Bill Settled :  <select id="BillSettled" name="BillSettled" required>
                                        <option value="false">False</option>
                                        <option value="true">True</option>
                                    </select>
                                    
                    <br><br><br>
                    
                    
                    <input id="btnSave" name="btnSave" type="button" value="Save" class="btn btn-primary">
                     
                    <input type="hidden" id="hidBillIDSave" name="hidBillIDSave" value="">
                    
                </form>
                
                <br>
                
                <div id="alertSuccess" class="alert alert-success"></div>
                <div id="alertError" class="alert alert-danger"></div>
                
                <br>
                
                <div id="divItemsGrid">
                </div>

The dynamically generated table is placed in the divItemsGrid div.

Here are the Jquery ajax code

// Save =================================================
$(document).on("click", "#btnSave", function(event) {
    
    // Clear alerts---------------------
    $("#alertSuccess").text("");
    $("#alertSuccess").hide();
    $("#alertError").text("");
    $("#alertError").hide();
    
    
    // Form validation-------------------
    var status = validateBillForm();
    if (status != true) {
        $("#alertError").text(status);
        $("#alertError").show();
        return;
    }   
    
    //var type = ($("#hidItemIDSave").val() == "") ? "POST" : "PUT";
    var type;
    if ($("#hidBillIDSave").val() == ""){
        type = "POST";
    }
    else{
        type = "PUT";
    }
    
    $.ajax(
        {
            url: "BillsAPI",
            type: type,
            data: $("#formBill").serialize(),
            dataType: "text",
            error: function(response, status, error) {
                console.log(response);
            },
            complete: function(response, status) 
            {
                onBillSaveComplete(response.responseText, status);
            }
            
        });
    
});


// UPDATE==========================================
$(document).on("click", ".btnUpdate", function(event) {
    $("#hidBillIDSave").val($(this).data("billID"));
    $("#UserID").val($(this).closest("tr").find('td:eq(0)').text());
    $("#BillingDate").val($(this).closest("tr").find('td:eq(1)').text());
    $("#UnitCost").val($(this).closest("tr").find('td:eq(2)').text());
    $("#UnitsUsed").val($(this).closest("tr").find('td:eq(3)').text());
    $("#ServiceCharge").val($(this).closest("tr").find('td:eq(4)').text());
    $("#BillSettled").val($(this).closest("tr").find('td:eq(5)').text());
});


// DELETE==============================================
$(document).on("click", ".btnRemove", function(event) {
    $.ajax(
        {
            url: "BillsAPI",
            type: "DELETE",
            data: "billID=" + $(this).data("billID"),
            dataType: "text",
            complete: function(response, status) {
                onBillDeleteComplete(response.responseText, status);
            }
        });
});

The update function sets the values into the form. If there is a hidden value then we use PUT to update the table. If not it becomes a POST.

I believe the error is here. Somehow the hidden billID value must not be getting set.

Below are the CRUD functions. They are a bit long but the dynamically generated table is in the read function.

//Create Bills
    public String createBill(String BillingDate, String unitCost, String unitsUsed, String serviceCharge, String billSettled, String userID) {
        
        String output = "";
        
        try {
            Connection con = connect();
            
            if(con == null) {
                return "Error while connecting to the database for inserting.";
            }
            
            //calculate total cost
            int totalCost = (Integer.parseInt(unitCost) * Integer.parseInt(unitsUsed)) + Integer.parseInt(serviceCharge);
            
            //create a prepared statement
            String query = "insert into bills (`billDate`, `unitCost`, `unitsUsed`, `serviceCharge`, `totalCost`, `settled`, `userID`)"
                    +" values(?,?,?,?,?,?,?)";
            
            PreparedStatement preparedStmt = con.prepareStatement(query);
            
            //converting String to util.Date to sql.Date
            java.util.Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(BillingDate);
            java.sql.Date  date2 = new java.sql.Date(date1.getTime());
            
            // binding values
            preparedStmt.setDate(1, date2);
            preparedStmt.setInt(2, Integer.parseInt(unitCost));
            preparedStmt.setInt(3, Integer.parseInt(unitsUsed));
            preparedStmt.setInt(4, Integer.parseInt(serviceCharge));
            preparedStmt.setInt(5, totalCost);
            preparedStmt.setBoolean(6, Boolean.parseBoolean(billSettled));
            preparedStmt.setInt(7, Integer.parseInt(userID));
            
            // execute the statement
            preparedStmt.execute();
            
            con.close();
            
            //output = "Inserted successfully";
            String newBills = readBills();
            output = "{"status":"success", "data": "" + newBills + ""}";
            
        }
        catch(Exception e) {
            //output = "Error while inserting the item.";
            output = "{"status":"error", "data": "Error while inserting the item."}";
            System.err.println(e.getMessage());
        }
        
        return output;
    }
    
    
    //Update Bills 
    //for settles bills
    public String updateSettledBills(String billID, String billSettled) {
        String output = "";
        
        Connection con = connect();
        
        try {
            
            if(con == null) {
                return "Error while connecting to the database for updating.";
            }
            
            //create prepared statement
            String query = "update bills set settled=? where billID=?";
            PreparedStatement preparedStmt = con.prepareStatement(query);
            
            //binding values
            preparedStmt.setBoolean(1, Boolean.parseBoolean(billSettled));
            preparedStmt.setInt(2, Integer.parseInt(billID));
            
            //execute statement
            preparedStmt.execute();
            
            con.close();
            
            //output = "Updated successfully";
            String newBills = readBills();
            output = "{"status":"success", "data": "" + newBills + ""}";
            
        }
        catch(Exception e) {
            //output = "Error while updating bill";
            output = "{"status":"error", "data": "Error while inserting the item."}";
            System.err.println(e.getMessage());
        }
        
        return output;
    }

    
    
    //Delete Bills
    public String deleteBill(String billID) {
        String output = "";
        
        try {
            Connection con = connect();
            
            if(con == null) {
                return "Error while connecting to the database for deleting."; 
            }
            
            //create prepared statement
            String query = "delete from bills where billID=?";
            PreparedStatement preparedStmt = con.prepareStatement(query);
            
            // binding values to prepared statement
            preparedStmt.setInt(1, Integer.parseInt(billID));
            
            // execute the statement
            preparedStmt.execute();
            
            con.close();
            
            //output = "Deleted successfully";
            String newBills = readBills();
            output = "{"status":"success", "data": "" + newBills + ""}";
        }
        catch(Exception e) {
            //output = "Error while deleting the bill.";
            output = "{"status":"error", "data": "Error while inserting the item."}";
            System.err.println(e.getMessage());
        }
        
        return output;
    }

Finally, here are the servlets.

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String output = billObj.createBill(
                    request.getParameter("BillingDate"),
                    request.getParameter("UnitCost"),
                    request.getParameter("UnitsUsed"),
                    request.getParameter("ServiceCharge"),
                    request.getParameter("BillSettled"),
                    request.getParameter("UserID"));
                    response.getWriter().write(output);
        
    }
    
    
    // Convert request parameters to a Map
    private static Map getParasMap(HttpServletRequest request) {
        Map<String, String> map = new HashMap<String, String>();
        try {
            Scanner scanner = new Scanner(request.getInputStream(), "UTF-8");
            String queryString = scanner.hasNext() ? scanner.useDelimiter("\A").next() : "";
            scanner.close();
            String[] params = queryString.split("&");
            for (String param : params) {
                String[] p = param.split("=");
                map.put(p[0], p[1]);
            }
        } catch (Exception e) {
        }
        return map;
    }

    /**
     * @see HttpServlet#doPut(HttpServletRequest, HttpServletResponse)
     */
    protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map paras = getParasMap(request);
        //System.out.println(paras.get("billID").toString());
        String output = billObj.updateSettledBills(
                paras.get("billID").toString(),
                paras.get("BillSettled").toString());
                response.getWriter().write(output);
                
    }

    /**
     * @see HttpServlet#doDelete(HttpServletRequest, HttpServletResponse)
     */
    protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map paras = getParasMap(request);
        String output = billObj.deleteBill(paras.get("billID").toString());
        response.getWriter().write(output);
    }

Sorry for the bloated post. I would greatly appreciate some with regards to this.

Typeerror: .reduce is not a function [closed]

I have the following code block giving me this error :

Uncaught TypeError: courseParts.reduce is not a function

import { coursePartsType } from "../types";

const Total = (courseParts: Array<coursePartsType>) => {
  return (
    <p>
      Number of exercises{" "}
      {courseParts.reduce((carry, part) => carry + part.exerciseCount, 0)}
    </p>
  );
};

export default Total;

I am passing courseParts as a prop into the ‘Total’ component:

const courseParts: Array<coursePartsType> = [
    {
      name: "Fundamentals",
      exerciseCount: 10,
    },
    {
      name: "Using props to pass data",
      exerciseCount: 7,
    },
    {
      name: "Deeper type usage",
      exerciseCount: 14,
    },
  ];

My type definition for coursePartsType :

export interface coursePartsType {
  name: string;
  exerciseCount: number;
}

Playing background music in a React app using Howler

So im using Howler to play background music when my React app is loaded. So I store ID of the instance of Howler(i.e is responsible for background music) using useState hook. I have a button in the app to toggle pause and play in the app. The problem is, when ever my site rerenders, a new instance is started playing and when I pause nothing pauses.

  const [aid, setAid] = useState(null);
  const [sp, setSp] = useState(false);

function handleBgSound() {
    if (sp) {
      amb.pause(aid);
      setSp(false)
    }
     else if (!sp) {
      setAid(amb.play())
      setSp(true)
    } else {
      amb.pause();
    }
  }

Im frustrated with this and would appreciate any help or leads!!

Why is it appearing for a split second? javascript

<!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>Document</title>

 

    <style>

        body {

            text-align: center;

        }

 

        table,

        th,

        td {

            border: 0px solid white;

            border-collapse: collapse;

            width: 45%;

            height: 55px;

            text-align: center;

            vertical-align: center;

            table-layout: fixed;

        }

 

        table.center {

            margin-left: auto;

            margin-right: auto;

        }

 

        .Tableheader {

            border: 0px solid white

        }

 

        .TableCell {

            background-color: rgb(252, 142, 215);

            border: 2px solid black;

        }

 

        .button {

            padding: 5px;

            background-color: #dcdcdc;

            border: 1px solid #666;

            color: #000;

            margin-top: 10px;

        }

 

        button:hover {

            color: yellow;

        }

 

        .TableCell:hover {

            background-color: rgb(255, 230, 0);

        }

        body {
  background-image: url('https://storage.pixteller.com/designs/designs-images/2019-03-27/05/simple-background-backgrounds-passion-simple-1-5c9b95bd34713.png');
}
    </style>

</head>

 

</body>
<div id="MainMenu">
    <form name="form1" action="#" onsubmit="required()">
        <ul>
    <h2>Hurkles the Game</h2>
    <p>Type in your name and click start to begin</p>
    <li><input type='text' name ='text1'/></li>
    <li class="rq">*Required Field</li>
        <li><input type="submit" name="submit" value="Submit" /></li>
</ul>
</div>

 <div id="Table">
<h2>Hurkles</h2>
<p> Click a Cell to Find Hurkles</p>
<table>

    <table id="tableID" class="center">

        <tr>
            <td id="R0C0" class="Tableheader"></td>
            <td id="R0C1" class="Tableheader">A</td>
            <td id="R0C2" class="Tableheader">B</td>
            <td id="R0C3" class="Tableheader">C</td>
            <td id="R0C4" class="Tableheader">D</td>
            <td id="R0C5" class="Tableheader">E</td>
            <td id="R0C6" class="Tableheader">F</td>
            <td id="R0C7" class="Tableheader">G</td>
            <td id="R0C8" class="Tableheader">H</td>
            <td id="R0C9" class="Tableheader">I</td>
            <td id="R0C10" class="Tableheader">J</td>
        </tr>

        <tr>
            <td id="R1C0" class="Tableheader">1</td>
            <td id="R1C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>

        <tr>
            <td id="R2C0" class="Tableheader">2</td>
            <td id="R2C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>

        <tr>
            <td id="R3C0" class="Tableheader">3</td>
            <td id="R3C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>

        <tr>
            <td id="R4C0" class="Tableheader">4</td>
            <td id="R4C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>

        <tr>
            <td id="R5C0" class="Tableheader">5</td>
            <td id="R5C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>

        <tr>
            <td id="R6C0" class="Tableheader">6</td>
            <td id="R6C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>

        <tr>
            <td id="R7C0" class="Tableheader">7</td>
            <td id="R7C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>

        <tr>
            <td id="R8C0" class="Tableheader">8</td>
            <td id="R8C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>

        <tr>
            <td id="R9C0" class="Tableheader">9</td>
            <td id="R9C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>

        <tr>
            <td id="R10C0" class="Tableheader">10</td>
            <td id="R10C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C10" class="TableCell" onclick="tableText('red')"></td>

        </tr>
        

    </table>
    <br>
    <br>
    <button type="button" id="reset" onclick="hideAll()">Start</button>
</div>

 

<script>
Table.style.display = "none";
MainMenu.style.display = "block";

function Start(){
    Table.style.display = "block"
    MainMenu.style.display = "none"
    
}
var input = document.getElementById("text1");
input.addEventListener("keypress", function(event) {
  if (event.key === "Enter") {
    event.preventDefault();
    document.getElementById("myBtn").click();
  }
});






   

     function tableText(col){
        if (typeof event!=='undefined')
            el=event.srcElement
            for (var i = 0; i < el.parentNode.cells.length; i++)
                el.parentNode.cells[i].style.backgroundColor=''
            el.style.backgroundColor=col
    }
    
    
    let colIndex = Math.floor(Math.random() * 8) + 1;
    let rowIndex = Math.floor(Math.random() * 8) + 1;
    console.log('col:' + ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'][colIndex-1], 'row:' + rowIndex);
    document.querySelector('#R' + rowIndex + 'C' + colIndex).onclick = () => { 
        tableText('green');
    }
    
    function hideAll(){
    Table.style.display = "none"
    MainMenu.style.display = "block"
}


function gameReset(){

}

function required(){
    var empt = document.forms["form1"]["text1"].value;
    if(empt == ""){
        alert("Please input your name");
    }
        else{
            Start()
        }
        
    
}

    

</script>

 

</html>

</script>

I’m new to coding and am trying to make a game for school, when i submit my name into a text box it is supposed to procede to the next page but it only flashes for a split second and was wondering why it does that? There is also some other error saying the ‘addeventlistner’ is wrong or something, though it was working fine before i put the alert message in. The code is in javascript, thanks.

How to update a nested object with mongo?

user :[{"id": 1, userObj: 
[{bookid: "1", library:"Oxford", taken:"true"}, 
{bookid: "2", library:"Cambridge", taken:"true"}]}
]

 tmpuser = await User.findOneAndUpdate({ 'userObj.bookid': req.body.bookid },  { $set: { 'userObj.taken': false }, }, { new: true }  );

What I would like to find an object with the property bookid and update the taken variable.
However when I try to do this I get this error:

code: 28, codeName: “PathNotViable”