Delete Elements Created by Event Listener

I’m trying to override an eventlistner so the accumulated text on the screen under “Message Will Add Here” disappears and I can enter new text whenever the user clicks ok in the alert window. But whatever method I use for this doesn’t do anything. Can you please tell me what I’m doing wrong? Here is my code:

HTML

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <div class="btncontainer">
      <button class="button"type="button" name="button">
        Over or Click Here
      </button>
      <p>MESSAGE WILL ADD HERE</p>
    </div>
    <script type="text/javascript" src="testc.js">
    </script>
  </body>
</html>

Javascript

var btn = document.querySelector('.button');

var count = 1;
var newpar;
var newval;
var container = document.getElementsByClassName('.btncontainer');

function e(){
  newpar = document.createElement('p');
  newpar.className = 'ps'
  newval = document.createTextNode('Was hovered ' + count + ' times');
  newpar.appendChild(newval);
  document.querySelector('.btncontainer').appendChild(newpar);
  count++;
}
btn.addEventListener('mouseover', e);

btn.addEventListener('click',function(){
  count-=1;
  alert(`The button was hovered over ${count} times`);
  count = 0;
  container.removeChild(newpar);
  btn.removeEventListener('mouseover', e);

})

Result

how to solve warning Use callback in setState when referencing the previous state

For this piece of code, I am getting eslint warning: warning Use callback in setState when referencing the previous state react/no-access-state-in-setstate

how can it be solved?

const sketch = await ImageManipulator.manipulateAsync(this.state.sketch, [{ rotate: 90 }], {
  base64: true,
  format: ImageManipulator.SaveFormat.PNG,
})
this.setState({ sketch: sketch.uri })

It is showing a warning for first-line(const sketch =....).

Javascript Scope problems on Push() [duplicate]

Im having trouble to understand the scope of an array in javascript. Im working with mongoose on nodejs and im kinda new to this language. Can someone help me to understand what im doing wrong? Thanks

const User = require(‘../models/Users’);

const friends_ofMain = (main_id) => {

var friendsIds = [];
const look4Friends =  User.findById(main_id, (err, result) => {

    for (let i = 0; i < result.length; i++) {
        friendsIds.push(result[i].friend_id);           
    }     
    
    return friendsIds;
})

}

module.exports = friends_ofMain;

How to make multiple role options in @discordjs/builders?

I am trying to make multiple role options for slash commands. I am using Slash Command builder – @discordjs/builders I have tried different ways but not working. This is my code:

    data: new SlashCommandBuilder()
        .setName('roles')
        .setDescription('Choices')
        .addRoleOption(role =>
          role.setName('role 1').setDescription('Choice 1').setRequired(false)
        )
        .addRoleOption(role =>
          role.setName('role 2').setDescription('Choice 2').setRequired(false)
        )
        .addRoleOption(role =>
          role.setName('role 3').setDescription('Choice 3').setRequired(false)
        )
        .addRoleOption(role =>
          role.setName('role 4').setDescription('Choice 4').setRequired(false)
        )
        .addRoleOption(role =>
          role.setName('role 5').setDescription('Choice 5').setRequired(false)
        ),

The errors I got for making this:

S[50035]: Invalid Form Body
3.options[0].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[1].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[2].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[3].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[4].name[STRING_TYPE_REGEX]: String value did not match validation regex.
    at Q.runRequest (/home/runner/ticket-1/node_modules/@discordjs/rest/dist/index.js:7:581)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Q.queueRequest (/home/runner/ticket-1/node_modules/@discordjs/rest/dist/index.js:5:2942)
    at async /home/runner/ticket-1/handler/slashCommand.js:35:9 {
  rawError: {
    code: 50035,
    errors: { '3': [Object] },
    message: 'Invalid Form Body'
  },
  code: 50035,
  status: 400,
  method: 'put',
  url: 'https://discord.com/api/v9/applications/935368903209672726/guilds/908385923673231481/commands',
  requestBody: {
    files: undefined,
    json: [ [Object], [Object], [Object], [Object] ]
  }
}

Please help me solve this problem.

HTML MVC TextBox AutoComplete ignore some inputs

I Have a TextBox that is hidden and its text will automatically change to a dropdown menu’s text, unless the optionLabel of the Dropdown menu is selected, in which case the user can enter a custom string (not from the dropdown menu).

I currently have autocomplete off for the textbox, because the options from the dropdown menu (when the textbox is hidden) would also show up for the autocomplete.
Is there a way to prevent some values from being stored in the autocomplete menu?

Everything else in the code works properly.

relevant code:

<div class="form-group">
    @Html.LabelFor(model => model.StudentId, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        <div id="SessionAttendDrop">
            @Html.DropDownListFor(model => model.StudentId, new SelectList(ViewBag.FirstStudentsIds, "Value", "Text"), defaultText, htmlAttributes: new { @class = "form-control", @style = "display:inline;" })
            <button class="btn btn-default" id="noStudentButton" type="button" onclick="setNoStudent()" >Custom</button>
        </div>
        @Html.ValidationMessageFor(model => model.StudentId, "", new { @class = "text-danger" })
        @Html.TextBoxFor(model => model.StudentName, htmlAttributes: new { @class = "form-control", @style = "display:inline;", @autocomplete = "off" })
        @Html.ValidationMessageFor(model => model.StudentName, "", new { @class = "text-danger" })

    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        //initionalize hidden element
        var text = $("option:selected", '#StudentId').text();
        //check if loaded option is a student: if so, show; if not, hide
        if ($('#StudentId').val() != "") {
            $('#StudentName').val(text);
            $('#StudentName').hide();
        } else {
            $('#StudentName').show();
        }


        $('#StudentId').change(function () {
            var text = $("option:selected", this).text();
            var selectedValue = $(this).val();
            if (selectedValue != "") {
                //if the option isn't the optionLabel option
                $('#StudentName').val(text);
                //document.getElementById("StudentName")
                $('#StudentName').hide();
            } else {
                $('#StudentName').val("");
                $('#StudentName').show();
            }
        });
    });
    function setNoStudent() {
        $("#StudentId").each(function () {
            var oldValue = this.value;
            this.value = "";
            if (oldValue != "") $(this).change();

        });
    }

Is WebGL fast than Canvas API for drawing a bunch of 2D objects❓❓

sorry if this is a dumb question.

I was trying to build a whiteboard as a side project using HTML canvas, and was wondering what’s the best technology for doing that.

My goal is to build a Miro like whiteboard that can draw/zoom/insert image etc.

Currently, I’m considering either using WebGL or using Canvas API. My understanding is that WebGL performs better for 3D rendering because it used GPU to do matrix multiplication, which is fast than CPU. However, in my case the whiteboard contains only 2D objects, would it still be faster to use WebGL (would it help to make Zoom in/out, drag and drop smoother)?

Thanks!

Enter number in reverse order in text field

I have a TextInput in react-native , I want to enter a number in order as 0.00 => 0.01 => 0.12 => 1.23 => 12.34 => 123.45 like this on each change text . CSS Direction “rtl” is not working . Looking for an algorithm to apply in my JS file for react-native textInput on

onChangeText={(amount) => this.onChangeText(amount)}

 onChangeText = (amount) => {
    //. Logic for reverse goes here

    this.setState({
      amount: newAmount,
      amountError: false,
    });
  };

How to work on lazy load(async loading) Vue without vue-cli or node?

I am very new to vue. I know that this one is easy with vue-cli but I need to learn this first without using the node.
I was making many template files and pages in different js files. Suddenly it hit my mind that what if a lot of file is requested and downloaded?
What I am trying to do is I am trying to fuse route and async component loading together for loading different pages when they are called.
Is there a way to do this? This is the code that I tried for my initial project.

 <html>
 <head>
 
      <script src="vue.js"></script>
  <script src="vue-route.js"></script>
    <script src="axios.min.js"></script>

 </head>
 <body>

<div id="app">
  <h1>Hello App!</h1>
  <p>
    <router-link to="/">Go to Home</router-link>
    <router-link to="/about">Go to About</router-link>
  </p>
  <router-view></router-view>
</div>
 <script>
 //axios.get("https://shohanlab.com")

const Home = { template: '<div>Home</div>' }
const AsyncComp =
  () =>
    new Promise((resolve, reject) => {
      resolve({
        template: About
      })
    })
const routes = [
  { path: '/', component: Home },
  { path: '/about', component: AsyncComp },
]

const router = VueRouter.createRouter({
  history: VueRouter.createWebHashHistory(),
  routes, // short for `routes: routes`
})

const app =Vue.createApp({})
app.use(router)
app.mount('#app')
  </script>
 </body>
</html>

As we can see in the code that The About.js is called even before I call it. In this way the page size will be very big.

How to call function from external js file?

I am trying to increment a button on click from an external js file. When i click on the button i am having an error message telling me that my function increment is undefined. How to reach a function for an external js file in html? Thanks in advance.
index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>webpack starterkit</title>
</head>
<body>
  <div id="app">
    <h1>People entered:</h1>
    <h2 id="count-el">0</h2>
  </div>
  <button id="increment-btn" onclick="increment()">Increment</button>
  <script type="text/javascript" src="scripts/index.js"></script>

</body>
</html>

index.js

let count = 0;
let countEl = document.getElementById("count-el");
console.log(countEl);
 document.getElementById("count-el").innerText = count;

function increment() {
  count = count + 1;
  countEl.innerText = count;

}
increment();

Reactjs Props not working and not showing in browser

import { Modal } from "react-bootstrap";
import { ButtonStyled } from "../..";

const ModalCom = (props) => {
 const [show, setShow] = useState(false);

const handleClose = () => setShow(false);
const handleShow = () => setShow(true);

return (
  <>
  <ButtonStyled onClick={handleShow}>{props.buttonName}</ButtonStyled>
    <Modal show={show} onHide={handleClose}>
      <Modal.Header closeButton>
        <Modal.Title>{props.title}</Modal.Title>
      </Modal.Header>
      <Modal.Body>
        <img src={props.image} alt='wallet' />
        <p>{props}</p>
      </Modal.Body>
    </Modal>
  </>
);
}

export default ModalCom;
 import { ButtonStyled, ModalCom } from '../../Components';

const Donate = () =>{
    return (
        <div>
            <ModalCom 
                buttonName='Ethereum'
                title='Ethereum Wallet'
                image=""
                p='23189189234923jn25890bdfs89fjnk245890'
             />
        </div>
    )
}

export default Donate;
import styled from 'styled-components'

const ButtonStyled = styled.button`
    background-color = ${({ bg }) => bg};
    color : ${({color}) => color};
    border-radius: 50px;
    padding: 10px 50px;
    border: none;
    box-shadow: 4px 5px 10px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    font-size: 20px;
    margin-top: 30px;
    &:hover{
        color: white;
        background-color: #62D3FC;
    }

`;
export default ButtonStyled;

why are my props not working? for the Modal file position it is in the modal component and Donate is in Pages Donate I want to send the name of the button, title, image, paragraph sent via props but in the browser it doesn’t appear what I want or even the data is not sent or Show in Browser
This I want showing but i can multiple modal

Syntax error: Unterminated string constant on Next.js fetch

Im having an error on my fetch api that is link to an outside URL , it is all working last week but now it is showing this error:

./pages/test.tsx:45:33

Syntax error: Unterminated string constant.

43 |
44 | var formdata = new FormData(e.target);

45 | const response = await fetch(“https:

This is my code:

   const response = await fetch("https://mistop.com/grow", {method: "POST",body: formdata,});

Error Image: Image