Mern React.js Can’t store Checkbox value o formdata

I am currently creating a react app for animal shelter and i am trying to store an array of value from the check box. i was able to populate the objects on my health schema on the CRUD create of my animal schema. now, i am clueless on how to put the values of checked checkboxes to the form data.

here is the health object on my Animal Schema

    healthcare: [
        {
            type: mongoose.Schema.ObjectId,
            ref: 'Health'
        }
    ],

frontend

const NewAnimal = () => {
    const [healthcares, setHealthcares] = useState([])
    
    ...
    
     const submitHandler = (e) => {
        e.preventDefault();
        formData.set('healthcares', healthcares);
        dispatch(newAnimal(formData))
    }
    
    ...
    
    <div className="col-6">
        <div className="form-group">
             <label htmlFor="health_field">Health</label>
             <hr/>
             {healths.map(health => (
                  <div key={health._id}>
                      <input
                         type="checkbox"
                         name="checkbox"
                         id="checkbox"
                         value={health._id}
                         onChange={e => setHealthcares.push(e.target.value)}
                       />
                       <label className="form-check-label">{health.name}</label>
                  </div>                                 
              ))}
         </div> 
     </div>

i tried to console.log the req.body and this is the result
enter image description here

Why .getMinutes() output as :0 instead of :00 in JavaScript?

The .getMinutes() method only outputs one integer ‘0’ instead of two integers ‘00’. Why does it do this and is there a simpler way to fix this?

Example:

        var dateDue = new Date("Fri Apr 22 2022 18:00:00");
        dateDue.getMinutes();   //Expected output: 18:00, got 18:0 instead?

For now I have been using if statement validation to add 0 whenever the minutes .Length returns as only being one character long instead of two.

        //Minutes display validation for dateDue
        var minutesDue = dateDue.getMinutes();
        if (minutesDue.Length === 1) {
        minutesDue = parseInt(dateDue.getMinutes()) + "0";

Coding language: JavaScript (vanilla)
Skill level: Beginner
Editor: Visual Studio Code
OS: Windows 7

Vue: Teleport inheritAttrs false not working

I’m trying to create a BaseOverlay component that basically teleports its content to a certain area of my application. It works just fine except there’s an issue when using it with v-show… I think because my component’s root is a Teleport that v-show won’t work because Teleport is a template.

I figured I could then use inheritAttrs: false and v-bind="$attrs" on the inner content… this throws a warning from Vue saying Runtime directive used on component with non-element root node. The directives will not function as intended. It results in v-show not working on MyComponent, but v-if does work.

Any clues as to what I’m doing wrong?

Example

App.vue

<script setup>
import MyComponent from "./MyComponent.vue";
import {ref} from "vue";
  
const showOverlay = ref(false);
function onClickButton() {
  showOverlay.value = !showOverlay.value;
}
</script>

<template>
  <button @click="onClickButton">
    Toggle Showing
  </button>
  <div id="overlays" />
  <div>
    Hello World
  </div>
  <MyComponent v-show="showOverlay" text="Doesn't work" />
  <MyComponent v-if="showOverlay" text="Works" />
</template>

BaseOverlay.vue

<template>
  <Teleport to="#overlays">
    <div
      class="overlay-container"
      v-bind="$attrs"
    >
      <slot />
    </div>
  </Teleport>
</template>

<script>
export default {
  name: "BaseOverlay",
  inheritAttrs: false,
};
</script>

MyComponent.vue

<template>
    <BaseOverlay>
    {{text}}
  </BaseOverlay>
</template>

<script>
import BaseOverlay from "./BaseOverlay.vue";

export default {
  name: "MyComponent",
  components: {
    BaseOverlay
  },
  props: {
    text: {
      type: String,
      default: ""
    }
  }
}
</script>

php isset($_post[]) and javascript form.submit

for some reason isset($_post) doesn’t work when i use js form.submit()
how i can resolve that without changing type of input from button to submit and just with using vanilla javascript because i need both of them.

code html:

<form name="user_verification" action="action.php" method="POST">
 Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="button" onclick="myFucntion(this)" name="submit" value="submit">
</form>

and here is the php script in action.php file

if(isset($_POST['submit'])) 
{
echo 'yes';
}else{
echo 'no';
}

and here is the php script in action.js file

function myFunction1(button)
{
//some code
const form=button.parentNode;
form.submit();}

EventLoop queue system limits

In the node EvenLoop there is callback execution limit for each queue phase.
So queue`s callback will be executed in each tick until in the queue will be nothing to execute or system limit is reached.

My question is : where I can check system limit for each tick queue ?

I already read a lot about it, but each article tells only about abstract limit without any explanation.

Uncaught TypeError: Cannot read properties of null (reading ‘innerHTML’)

When trying to make a script that displays certain statements every 5 seconds, I get an error stating
Uncaught TypeError: Cannot read properties of null (reading 'innerHTML').

How do i fix this? This is the code:

fact_displayer = () => {
    var fact = facts[Math.floor(Math.random() * facts.length)];
    var i = 0;
    var timer = setInterval(function() {
        document.getElementById("fact").innerHTML += fact[i];
        i++;
        if (i >= fact.length) {
            clearInterval(timer);
            setTimeout(() => {
                document.getElementById("fact").innerHTML = "";
                setTimeout(() => {
                    scrolltitle(fact);
                }, 1000);
            }, 1000);
        }
    }, 100);
}

// runs fact_displayer every 5 seconds
setInterval(fact_displayer, 5000);

How to use checkbox to activate image ALT atribute to show on the image?

I need to make a function when I click on check box I can can see image name (Alt=”bla bla”) when mouse hovered on the picture. I apreciate the help!

Js –

function show(){
  var images = document.querySelectorAll('gr');
  var elem = document.getElementById('chb');

  images.forEach(function(image) {
  image.addEventListener('click', function() {
    elem.innerHTML = image.getAttribute('alt');
    });
  });
}
 
<div class="grupe" id="gr">

<img src="https://upload.wikimedia.org/wikipedia/commons/c/c8/Altja_j%C3%B5gi_Lahemaal.jpg" alt=MiskoUpe style="width:170px;height: 120px;margin: 0px 40px;">
     
<img src="https://media.istockphoto.com/photos/mountain-landscape-picture-id517188688?k=20&m=517188688&s=612x612&w=0&h=i38qBm2P-6V4vZVEaMy_TaTEaoCMkYhvLCysE7yJQ5Q=" alt=Kalnai style="width:180px;height: 122px; margin: 0px 40px;">

<img src="https://natureconservancy-h.assetsadobe.com/is/image/content/dam/tnc/nature/en/photos/Zugpsitze_mountain.jpg?crop=0,176,3008,1654&wid=4000&hei=2200&scl=0.752" alt=KalnaiIrEzeras style="width:190px;height: 120px; margin: 0px 40px;">

<img src="https://images.assettype.com/fortuneindia%2F2020-06%2Fef53f9be-f257-4aa3-9af5-6ca1a9f33a86%2Fclose_up_photography_of_leaves_with_droplets_807598.jpg?rect=0,607,4128,2322&w=1250&q=60" alt=Lapai style="width:170px;height: 120px; margin: 0px 40px;">

</div>

            
<div class="check">
    <label for="checkb"> <b>Rodyti aprasyma:</b> </label>
    <input type="checkbox" id="chb" onclick="show()" />
</div> 
       

Can anyone help this out? 🙂

Handling / Hiding Endpoint Calls while hosting

I want to encrypt my api call or say Endpoint from react frontend

Is it possible

For example
Backend Api :
enter code herehttps://teacher.com/abc/new

Which is a post method

I am making the call from frontend
So it shows the call and even the query in url which is vulnerable

Can it be encrypted

Output different property of object

Sorry for the vague title, if anyone has a better one, please let me know and I will update it.

I have the following code that goes through 2 arrays of objects. For each “location” it creates a subheading based on the locations array and then adds information relevant to that location based on the locationContent array.

function panelContent() {  
    
    const panelInformation = locationContent.reduce((acc,el) => {
      if (acc[el.location]) acc[el.location].push(el)
      else acc[el.location] = [el]; 
      return acc;
    }, {});

    let content = '';
    for (let location in panelInformation) {
      // Code that needs changing is here
      content += '<hr class="panelHr"><h2 class="panelSubheading">' + location.replace(/s+/g, '') + '</h2>';    


      for (let locationContent of panelInformation[location]) {
        content += '<a href="' + locationContent.image + '" data-fancybox="CarloVannucci" data-caption="' + locationContent.caption + '"><img class="panelImg" src="' + locationContent.image +'"></a><p class="panelParagraph">'+ locationContent.caption +'</p>';
      }
    }

    $('.panel').html(content);    
};

However, I would like to make a modification to the code, where for the subheading, instead of just writing the value of the location property, I would like it to demonstrate a different string, based on another property of the array.

So using the following as an example:

let locations = [
    {location: 'Viareggio',
     name: 'Viareggio, Italy (1937); pre-war'
    },
]

I would like it to display the value of the ‘name’ property. I have tried a few variations of the code, however all of them keep giving me various errors, so I am hoping someone can assist. Thank you.

Get the ID of firebase document

so I have this collection:

//console.log(currentUserUID)


   await fire
       .firestore()
       .collection('userEventsCal')
       .doc(currentUserUID)
       .collection(eventID)
       .get()

I am calling this in a new page, so I don’t have access to the eventID. I am trying to figure out how to do it with just

await fire
           .firestore()
           .collection('userEventsCal')
           .doc(currentUserUID)

but it’s failing. Is my logic wrong or is this just impossible to do?

 await fire
       .firestore()
       .collection('userEventsCal')
       .doc(currentUserUID)
       .get().then((doc) => {
        if (doc.exists) {
            console.log("Doc data lol:", doc.data());
        } else {
            // doc.data() will be undefined in this case
            console.log("No such document!");
        }
    }).catch((error) => {
        console.log("Error getting document:", error);
    });

my searching an array function fail in js

Hi I made a function to search an array for an objective Wich is a parameter by jumping around the array by generating an index by combining the start and end index in math.random both are parameters but it doesn’t work I don’t know why
Here’s my code in Js

let arrayTest = ['hi', 6, 8, true, null]


function SearchArray(array, startIndex, endIndex, objective){
  
   let JumpIndex = Math.floor(Math.random() * endIndex + startIndex)
   console.log(JumpIndex)
   
   if(array[JumpIndex] == objective){
     
     return array[JumpIndex]
     
     console.log(array[JumpIndex])
     
   }else{
     
     JumpIndex = Math.floor(Math.random() * endIndex + startIndex)
     
   }
}

SearchArray(arrayTest, 0, 5, 'hi')

Redirect modal form (PHP-JS-HTML5)

I try to learn frontend and backend. I create a simple login form with bootstrap modal but i have this problem. When i submit the data the modal disappear and i see the message only if i click to the button of my modal. How can i prevenent this event? Sorry for my English.
This is the code

PHP MODAL

    <div class="modal fade" id="loginModal" tabindex="-1" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog">
    <div class="modal-content" id="modalContent">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Login</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" id="closeForm"></button>
        </div>
       <div class="modal-body">
        <div id="errori" >
        <!-- controllo sui campi lasciati vuoi !-->
      <?php 
      if(!empty($_SESSION['errore'])){ ?> 

      <div class="alert alert-danger"><?=$_SESSION['errore'] ?> </div>
      <?php
      $_SESSION['errore']='';
      }
      ?>
  <!-- fine controllo !-->
    </div>

    <form action="signup.php" method="POST" id="formLogin">
    <div class="mb-3">
    <label for="email" class="form-label">Indirizzo email</label>
    <input type="email" class="form-control" id="email" name="email" aria-describedby="emailHelp">
    <div id="emailHelp" class="form-text">Il tuo indirizzo email</div>
  </div>
  <div class="mb-3">
    <label for="exampleInputPassword1" class="form-label">Password</label>
    <input type="password" class="form-control" id="password" name="password">
  </div>
  <div class="mb-3 form-check">
    <input value="1" type="checkbox" class="form-check-input" id="remember" name="remember">
    <label class="form-check-label" for="exampleCheck1">Ricordami</label>
  </div>
  <div class="mb-3">
    <p> Non sei ancora Registrato? <a data-bs-toggle="modal" href="#regModal" data-bs-target="#regModal" onclick="clickreg()"> Clicca qui</a> per registrarti </p>
  </div>
  <button type="submit" id="regBtn" class="btn btn-primary">Invia</button>
    </form>
      </div>
      <div class="modal-footer">
          <!--
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
        !-->
      </div>
    </div>
  </div>
</div>

<?php include 'regModal.php'; ?>


<script>
function clickreg(){
    $('#loginModal').modal("hide");
    $('#regModal').modal("show");
}
</script>
<script>
$('#formLogin').on('submit', function() {
  $('#loginModal').addClass('modal fade show').css('display','block');

});
</script>

SIGNUP.PHP. This part of code check if the data insert in the form are blanck and save all in a session variable named “error”

    <?php 
if(!isset($_SESSION)) 
{ 
    session_start(); 
} 

$errore= '';
if(empty($_POST['email'])){
   $errore .= 'Email richiesta <br>';
}
if(empty($_POST['password'])){
    $errore .= 'Password richiesta';
}
    if(!empty($errore)){
    $_SESSION['errore'] = $errore;
    
}