Why is the print function printing the whole page?

I am trying to print the content of a specific modal. I have this code so far:

<div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
        <button type="button" id="btnSave" onclick="save()" class="btn btn-success">Save</button>
        <!--<button id="btnPrint" type="button" class="btn btn-default">Print</button>-->
        <!-- <button id="btnPrint" type="button" class="btn btn-default">Print</button>-->
            <!-- <button type="button" onclick="printDiv('print-content')" class="btn btn-primary">Print</button> -->
      </div>

And this is the javascript code:

 document.getElementById("btnPrint").onclick = function () {
     printElement(document.getElementById("printThis"));
 }

 function printElement(elem) {
     var domClone = elem.cloneNode(true);
    
     var $printSection = document.getElementById("printSection");
    
     if (!$printSection) {
         var $printSection = document.createElement("div");
         $printSection.id = "printSection";
         document.body.appendChild($printSection);
     }
    
     $printSection.innerHTML = "";
     $printSection.appendChild(domClone);
     window.print();
 }

But even doing <div id="printThis"><p>test</p></div> prints the whole page instead of just test.

What is a rich object?

I’m learning Express. While doing a tutorial, I stopped to try to figure out why the tutor used express.urlencoded({extended: false}). I learned what url-encoding is, and I’ve read descriptions on the true or false values for the extended option, but I’m still not sure why we have to put extended: false in this app. I know it’s because we are storing input from a form, and that input has to be parsed to be usable in the req.body object. But the best documentation on the extended option says that a true value uses the qs library and allows for rich objects and arrays in our body object, whereas false uses the querystring library which only allows a string or an array.

So, is a “rich” object just a nested object? (Same with array?) And why would we set extended to false?

Sequelize filter the included tables by where

I am trying to findAll records included nested tables, but did not understand how could I filter included tables by where clause. Here are the words:

const players = await PlayerService.findPlayers({
    attributes: { exclude: ['password'] },
    include: [
      { all: true },
      {
        model: Team,
        as: 'captainTeams',
        attributes: {exclude: ['createdAt', 'updatedAt']}
      },
      {
        model: Team,
        as: 'teams',
        where: { type: 1 },
        required: true,
        through: {attributes: []},
        attributes: {exclude: ['createdAt', 'updatedAt']}
      }
    ]
  })

Here is the result:

enter image description here

If I delete where and required from including Team clause, here is the result:

enter image description here

I would like to filter teams.type=2. Could you help me ?

Looping through two arrays having different lengths and then making request

I have a unique situation where I have 2 arrays. One array has a length of 9 items and array Two has a length of 29 items. I am trying to figure out how to iterate through array one that has my ids and make a request for each individual string in array two.

Array One ex:
["70884", "113062", "115102", "112878", "114683", "120078", "114682", "120594", "120093"]

Array Two ex:
[
   {
      "key":"Baseball"
   },
   {
      "key":"Beach volleyball"
   },
   {
      "key":"Softball"
   },
   {
      "key":"Soccer"
   },
   {
      "key":"Basketball"
   },
   {
      "key":"Track and field"
   },
   {
      "key":"Action sports"
   },
   {
      "key":"Auto racing"
   },
   {
      "key":"Gymnastics"
   },
   {
      "key":"Volleyball"
   },
   {
      "key":"Hockey"
   },
   {
      "key":"Mixed martial arts"
   },
   {
      "key":"Golf"
   },
   {
      "key":"Playoff sports"
   },
   {
      "key":"Boxing"
   },
   {
      "key":"Lacrosse"
   }
]

example of what these requests would like:
http://localhost:3003/api/events/70884/Baseball
http://localhost:3003/api/events/113062/Baseball
http://localhost:3003/api/events/115102/Baseball
http://localhost:3003/api/events/112878/Baseball
....
http://localhost:3003/api/events/70884/Beach%20volleyball
http://localhost:3003/api/events/113062/Beach%20volleyball
http://localhost:3003/api/events/115102/Beach%20volleyball
http://localhost:3003/api/events/112878/Beach%20volleyball
....
and so on....And push the request to objects in an Array

Not sure how to approach this:
await Promise.all(
    mySports.map((sport, idx) => {
        const trimIds = myIds[idx].slice(0, 9)
        axios.get(`/api/Events/${trimIds}/${sport.key}`).then((response) => {
          myArr.push(
            response.data
          )
          console.log("myArr", myArr)
        })
    }
    )
  )


My Desired Structure would be end being a 2d Array:

[
    {
       "baseball":{
          "events":[
             {
                "event":"my event"
             },
             {
                "event":"my event"
             },
             {
                "event":"my event"
             }
          ]
       }
    },
    {
       "Beach volleyball":{
          "events":[
             {
                "event":"my event"
             },
             {
                "event":"my event"
             },
             {
                "event":"my event"
             }
          ]
       }
    },
    {
        "Softball":{
           "events":[
              {
                 "event":"my event"
              },
              {
                 "event":"my event"
              },
              {
                 "event":"my event"
              }
           ]
        }
     }
 ]

I’m running a loop to print the same variable using var and let [duplicate]

 for(var i = 0; i < 10; i++) {
    console.log(i);
    setTimeout(function() {
        console.log(`The number is ${i}`);
    }, 1000);
}

This above block of code log 0-9 correctly but then prints “The number is 10” ten times instead of printing “The number is 0”, “The number is 1” and so on

However, if I change the variable declaration to ‘let’. Then it prints out correctly.

    for(let i = 0; i < 10; i++) {
    console.log(i);
    setTimeout(function() {
        console.log(`The number is ${i}`);
    }, 1000);
}

This above block of code prints the statements correctly. Each statement is printed after a delay of one second like “The number is 0”, “The number is 1” and so on.

I’m not able to understand what is going on here. Can someone break it down for me?

JS AJAX doesn’t post data to php / using Visual Studio Code

The JS part should send data to a php script on button click.

The data doesn’t get to the php script, as echo would show it, but I don’t get any errors.

I am using Visual Studio Code

let cB = document.getElementById("confirmButton");
let label = document.getElementById("label");

    cB.onclick = function() {

  $.ajax({
   url: 'http://example.com/send.php',
   type: 'post',
   data: "input=" + "sss",
   success: function(response){ label.innerHTML = "done" }
  });
}

This is the send.php

<?php

$host = '';
$database = '';
$user = '';
$pswd = '';

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$conn = new mysqli($host, $user, $pswd, $database);

if ($conn->connect_error) {
 die("Connection failed:" . $conn->connect_error);
echo "Connection failed.";
}

echo "Connection successful";

$say = $_POST['input'];

echo $say;

$sql = $conn->prepare("INSERT INTO Example (Letters) VALUES(?)");

$sql->bind_param('s', $say);

$sql->execute();


 echo "Created successfully";

$sql->close();
$conn->close();

?>

KML – Garmin Tracks live network link

I am trying to track a relative who is hiking the PCT using the KML from his Garmin inReach Mini. I’ve put together several pages on my personal website so our family can keep up with him and what’s happening on the trail. What I need help with is the map I’ve set up using the Google Maps Javascript API and this code (https://developers.google.com/maps/documentation/javascript/kml). I want the map to update as he progresses through the trail via the Network Link.

I’ve tried to plug in two of the three KML files available from his Garmin account to get live updates sent to the map. I’ve taken the suggested ShareFeed KML file for Google Earth that’s provided by Garmin as well as the Raw KML file and combined them. This has been most effective to provide the entire track of the journey rather than his most recent location. I’ve found that I have to alter the UTC time in the address for the KML to get an update on his trip. Essentially each morning I update the UTC time in the address and then his location updates. What can I do so the location automatically updates via the Network Link without having to alter the code or address? Keep in mind I am not a developer. I’m a data analyst that built html sites as a teenager. So I know a little but not a lot.

<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Dylan's PCT Hike</title>
    <style>
      html, body {
        height: 480px;
        padding: 0;
        margin: 0;
        }
      #map {
       height: 480px;
       width: 100%;
       overflow: hidden;
       float: left;
       border: thin solid #333;
       }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <div id="capture"></div>
    <script>
      var map;
      var src = 'https://share.garmin.com/Feed/ShareLoader/DylanPCT?d1=2022-05-09T01:06z';
      var src = 'https://share.garmin.com/Feed/Share/DylanPCT?d1=2022-05-09T01:06z';
      
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          center: new google.maps.LatLng(-19.257753, 146.823688),
          zoom: 1,
          mapTypeId: 'satellite'
        });

        var kmlLayer = new google.maps.KmlLayer(src, {
          suppressInfoWindows: false,
          preserveViewport: false,
          map: map
        });
      }
    </script>
    <script async
    src="https://maps.googleapis.com/maps/api/js?key=MY-API-KEY-WOULD-BE-HERE&callback=initMap">
    </script>
  </body>
</html> ```

Thanks!

REACT- Making 2 different dynamic displays depending on a selection checkboxes ( everything is on the same page now)

depending on the selection of my user Change the type or Choose the comments (he can select only one choice), there will be a different display, but my code displayed both options in the same page.

So, in the begining there are only 2 checkboxes Change the type or Choose the comments then depending on the selection the display appears

 export default function App(){
  ...
  return (
    <>
     {/* Step 1- 2 checkboxes are displayed */}
      <form onSubmit={handleSubmit}>
        <input type="checkbox" onChange={(e) => setType(e.target.value)} />
        <span className="text-md p-1 font-bold  leading-8 text-gray-500">
          Change the type{" "}
        </span>
        <input type="checkbox" onChange={(e) => setComment(e.target.value)} />
        <span className="text-md p-1 font-bold  leading-8 text-gray-500">
          Choose the comments{" "}
        </span>
      </form>
      
      {/*Step 2 - if setType ==true then display */}
      <form onSubmit={handleSubmit}>
        <input
          type="text"
          value={menu}
          placeholder="Menu"
          onChange={(e) => setMenu(e.target.value)}
        />
        <div className="text-md font-bold  text-gray-500 flex flex-wrap gap-x-2 ">
          Type : <CustomDropdown options={LOCATION} isMulti={false} />
        </div>
        <label className="mr-3 h-6 text-md font-bold  leading-8 text-gray-500">
          Location:
        </label>
        <input
          type="text"
          value={location}
          placeholder="Location"
          onChange={(e) => setLocation(e.target.value)}
        />
      </form>

      {/*Step 2 - if setComment ==true (selected) then display */}
      <form onSubmit={handleSubmit}>
        <Comments />
        <input
          type="text"
          value={menu}
          placeholder="Menu"
          onChange={(e) => setMenu(e.target.value)}
        />
        <div className="text-md font-bold  text-gray-500 flex flex-wrap gap-x-2 ">
          Type : <CustomDropdown options={LOCATION} isMulti={false} />
        </div>
        <label className="mr-3 h-6 text-md font-bold  leading-8 text-gray-500">
          Location:
        </label>
        <input
          type="text"
          value={location}
          placeholder="Location"
          onChange={(e) => setLocation(e.target.value)}
        />
      </form>
    </>
  );
}

Here is my code

Adding logs within a wrapped function

I have created a function wrapper to help give me various print statements:

function fnWrapper(fn, verbosity=false) {
    return function(...rest) {
        if (verbosity) console.log(`Calling "${fn.name}(${rest})"`)
        const res = fn(...rest); // possible to add debugging **within** this wrapped function?
        if (verbosity) console.log('==>', res)
        return res;
    }
}
function add(x,y) {
     return x===0 ? y : add(x-1, y+1);
}
const add2 = fnWrapper(add, true);

add2(2,3);
// Calling "add(2,3)"
// ==> 5

Is it possible to add debugging within the function itself, for example, at its most basic to translate a function such as the following:

function something(x,y) {
    console.log(arguments); // add this in
    ...
}

So for the above function it would make the add become:

const add = (x,y) => {
    console.log(arguments);
    x===0 ? y : add(x-1, y+1);
}

If so, how could that be done?

Type Error: How do I get a method to execute like a function in Javascript?

I was trying to create a Javascript function in HTML,which should create a rectangle and set the size to the likings of the user with this code:

class Rectangle{
  constructor(height, width){
    this.height = height;
    this.width = width;

  function createRectangle(Rectangle){
    var input1 = document.getElementbyId("1stinput").value;
    var input2 = document.getElementbyId("#2ndinput").value;
    var input1int = parseFloat(input1);
    var input2int = parseFloat(input2);
    var Rectangle1 = new Rectangle(this.height=input1int, this.width=input2int);};
    document.querySelector("Rectangle").setAttribute('width', parseFloat(Rectangle1.width));
    document.querySelector("Rectangle").setAttribute('height', parseFloat(Rectangle1.height));
};
};
</script>
<input type="text" name="" value="" id="1stinput">
<input type="text" name="" value="" id="2ndinput">
<button onclick=Rectangle.createRectangle(Rectangle)>create</button>
<svg width=0 height=0>
  <rect width=0 height=0 style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)" id="Rectangle"/>
</svg>

But that didn’t work,I got this Error:

Uncaught TypeError: Rectangle.createRectangle is not a function
    at HTMLButtonElement.onclick

So I think,that createRectangle shoud be a method,but I don’t know how to implement methods in the button,can someone Please help me?
That would be very nice,thank you!!!

How do I filter and then use API Data?

I have this sports API and I want to be able to pull only certain league ids from this data and use those selected leagues to display them.

here is the API Call code:

const settings = {
"async": true,
"crossDomain": true,
"url": "https://v3.football.api-sports.io/fixtures?date=2021-04-07",
"method": "GET",
"headers": {
    "X-RapidAPI-Host": "v3.football.api-sports.io",
    "X-RapidAPI-Key": "MY-API-KEY"
}

};

the format of the API data is as follows:

Here is the ID that identifies each game (there are 307 games in the picture). I have a list of IDs (I assume I make an array with them) that I want to keep and I want to get rid of the rest of the IDs from the data

After this I want to display the information of the IDs that I have kept from the data.

Any help is appreciated thanks!

Functionality to search bar

I am working on making a search bar that will filter my site for reports(urls) based on what is typed in. It currently works sort of. It will filter the items but you have the have the menus expanded for it to filter them.

I am looking for a way to either only have the results that match the search show(get rid of the headers for the dropdowns and only show links). OR to auto expand the dropdowns when a character is typed into the search bar

(closest I could get for a repeatable example.)

</head>
<style>
.evolve .barTop {
    -webkit-transform : rotate(-45deg) translate(-8px, 8px) ;
    transform: rotate(-45deg) translate(-8px, 8px);
}

.evolve .barMid {
    opacity : 0;
    transition: 0.1s ease-in;
}

.evolve .barBot {
    -webkit-transform : rotate(-45deg) translate(-8px, -8px) ;
    transform: rotate(45deg) translate(-8px, -8px);
}

#main {
    transition: margin-left 0.5s;
    position: relative
}

.content {
    max-height: 0px;
    overflow: hidden;
    background-color: transparent;
    transition: max-height 1s ease-out;
    box-shadow : inset 0px 0px 7px 7px rgba(0,0,0,0.15);
}

.content .content-stuff {
    background-color: #20396120;
    border-left: outset #203961 13px;
    padding: .5rem 1rem;

}

.content .content-stuff .subcontent {
    max-height: 0px;
    overflow: hidden;
    background-color: transparent;
    transition: max-height .75s ease-out;
}

.content .content-stuff .subcontent .subcontent-stuff {
    border-bottom: solid grey 3px;
    padding: .5rem;

}

.button:checked + .header + .content {
    max-height: inherit;
}

.subbutton:checked +  .subheader + .subcontent {
    max-height: inherit;
}

.content .content-stuff .clickLink {
    cursor: pointer;
}


hr {
    border-style: solid;
    color: #20396150;
    border-height: .5px;

}

ul.Links {
  list-style-type: none;
  margin: 0;
  padding: 0px;
}

li:not(:last-child) {
    margin-bottom: 10px;
}



.fade-in-image {
    position : absolute;
    top: 13px;
    left: 60px;
    transition: FadeIn 1.0s ease-in;
}

.fade-in-image h2{
    margin-top : 1px;
    margin-left : 45px;
    color : #fca445;
    white-space: nowrap;
    font-family: 'Roboto', sans-serif;
    font-weight : 400;
    text-shadow:  3px 6px 6px rgba(0,0,0,0.19),
                 0px -7.5px 15px rgba(255,255,255,0.10);;

}

@keyframes slide-right {
    0% { margin-left : -10%};
    100{ margin-left : 80%};
}


.fade-in-image img {
    position : absolute;
    animation: move 3s ease infinite;
}

@keyframes move {
    0%  { margin-left : -10px;}
    5%  { margin-left : -9.25px;}
    10%  { margin-left : -10px;}
    15%  { margin-left : -10px;}
    75% {margin-left : 3px;}
    80%  { margin-left : -11.5px;}
    85%  { margin-left : -5.5px;}
    87.25% { margin-left : -11px;}
    90%  { margin-left : -7px;}
    95% { margin-left : -10.5px;}
    97.5%  { margin-left : -9.25px;}
    100% { margin-left : -10px;}
  }
}



<!-- popup code credit: codeconvey.com-->

.sidebar .pop {
  position: absolute;
  width: 50%;
  margin: auto;
  padding: 20px;
  height: 50%;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

@media (max-width: 640px) {
  .pop {
    position: relative;
    width: 100%;
  }
}

.sidebar .pop .modal {
  z-index: 2;
  opacity: 0;
  visibility: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  -webkit-transition: opacity 500ms ease-in-out;
  transition: opacity 500ms ease-in-out;
}

.sidebar .pop .modal__inner {
  -webkit-transform: translate(-50%, -50%) scale(0.75);
          transform: translate(-50%, -50%) scale(0.75);
  top: 50%;
  left: 50%;
  width: 50%;
  background: white;
  padding: 30px;
  position: absolute;
  color: black;
}
@media (max-width: 640px) {
  .pop .modal__inner {
    width: 100%;
  }
}

.sidebar .btn-close{
    color: #fff;
    text-align: center;
}

.sidebar .pop label {
    position: absolute;
    top: 8px;
    right:  55px;
    padding: 1px 19px 1px 19px;
    font-size: 45px;
    cursor: pointer;
    transition: 0.2s;
    color : #fca445;
}

.sidebar .pop label.open:hover {
    box-shadow :
        0 2.8px 2.2px rgba(0, 0, 0, 0.034),
        0 6.7px 5.3px rgba(0, 0, 0, 0.048),
        0 12.5px 10px rgba(0, 0, 0, 0.06),
        0 22.3px 17.9px rgba(0, 0, 0, 0.072),
        0 41.8px 33.4px rgba(0, 0, 0, 0.086),
        0 100px 80px rgba(0, 0, 0, 0.12);
    border-radius: 5px;
    background-color: #33d62b60;
    font-size: 45px;
}

.sidebar .pop input {
  display: none;
}
.sidebar .pop input:checked + .modal {
  opacity: 1;
  visibility: visible;
}
.sidebar .pop input:checked + .modal .modal__inner {
  -webkit-transform: translate(-50%, -50%) scale(1);
          transform: translate(-50%, -50%) scale(1);
  -webkit-transition: all 200ms ease-in-out;
  transition: all 200ms ease-in-out;
}
.sidebar .pop input:checked + .modal .modal__inner p {
  font-size: 1.25rem;
  line-height: 125%;
}
.sidebar .pop input:checked + .modal label {
    position: absolute;
    top: 0;
    right: 0;
    padding: 4px 8px 4px 8px;
    font-size: 20px;
    cursor: pointer;
    transition: 0.2s;
    color : #000;
    -webkit-transition: all 200ms ease-in-out;
    transition: all 200ms ease-in-out;
}
.sidebar .pop input:checked + .modal label:hover {
  background-color: #ff141860;
}
</style>
<body>
<div id="Sidebar" class="sidebar">
    <p style="text-align:center;"><input id="searchbar" onkeyup="searchSite()" type="text" name="search" placeholder="Search" title="Report or Category Name" style="width: 300px;" /></p>
<input id="OpsButton" class = "button" type="checkbox">
        <label for="OpsButton" class = "header">Operations</label>
        <div class = "content" >
            <div class = "content-stuff">
                <input id="Button1" class = "subbutton" type="checkbox">
                <label for="Button1" class = "subheader">Header1</label>
                <div class = "subcontent">
                    <div class = "subcontent-stuff" >
                        <ul class = "Links">
                            <li><a title="Region" href="X" target="bodyinfo">Region</a></li>
                            <li><a title="range" href="X" target="bodyinfo">range</a></li>
                        </ul>
                    </div>
                </div>
                <input id="FinancialButton" class = "subbutton" type="checkbox">
                <label for="FinancialButton" class = "subheader">Financials</label>
                <div class = "subcontent">
                    <div class = "subcontent-stuff" >
                        <ul  class = "Links">
                            <li><a title="Region2" href="X" target="bodyinfo">Region2</a></li>
                            <li><a title="range2" href="X" target="bodyinfo">range2</a></li>
                        </ul>
                    </div>
                </div>
                <p>
            </p><ul class="Links">
                <li><a href="X" target="bodyinfo">Turnover Report</a></li>
            </ul>
            <p></p>
            </div>
        </div>
</div>
  
<script>
function searchSite() {
  var input, filter, ul, li, a, i, txtValue;
  input = document.getElementById('searchbar');
  filter = input.value.toUpperCase();
  ul = document.getElementById("Sidebar");
  li = ul.getElementsByTagName('li');
  closestClass = ul.closest('.parent');

  for (i = 0; i < li.length; i++) {
    a = li[i].getElementsByTagName("a")[0];
    txtValue = a.textContent || a.innerText;
    if (txtValue.toUpperCase().indexOf(filter) > -1) {
      li[i].style.display = "";
    } else {
      li[i].style.display = "none";
    }
  }
}
</script>
</body>
</html>

Improve debugging output of a recursive function

I have the following recursive function to count the number of ways change can be returned given various coin denominations:

function makeChange(amount, coins) {
    // Note: using Floats here will not work
    console.log(`Amount: ${amount}, Coins: ${coins}`);
    return (amount === 0)  ? 1 :
           (amount < 0)    ? 0 :
           (!coins.length) ? 0 :
                             makeChange(amount-coins[0], coins) 
                           + makeChange(amount, coins.slice(1));
}
console.log(
    makeChange(11, [7,3,1])
);

However, I’d like to improve the visual-aspect of the debugging to really see what might be going on behind the scenes of the recursive function — almost like each level of the stack and how to show that. I’ve improved it to pass a level parameter so I can do indentation and I then have:

function makeChange(amount, coins, level=0) {
    console.log(`${' '.repeat(level)}Amount: ${amount}, Coins: ${coins}`);
    return (amount === 0)  ? 1 :
           (amount < 0)    ? 0 :
           (!coins.length) ? 0 :
                             makeChange(amount-coins[0], coins, level+1) 
                           + makeChange(amount, coins.slice(1), level+1);
}
console.log(
    makeChange(10, [5,1])
);

But even this is a bit difficult to understand as it has so much superfluous input. What might be a better way to add in various debug helpers to better visualize this?