Why does my dragover event prevent my drop event from firing?

i’m tring to create a drag and drop in a football website.
the drop event dosen’ t fire and i don’t know why.

this is the code where i create the span whith name of the player

let spanAttaccanti = document.createElement("span");
    spanAttaccanti.addEventListener("dragstart", onDragStart);
    spanAttaccanti.addEventListener("dragend",dragEnd)
    spanAttaccanti.addEventListener("dragover", ondragover);
    spanAttaccanti.addEventListener("dragenter", ondragenter);
    spanAttaccanti.addEventListener("dragleave", onDragLeave);
      spanAttaccanti.addEventListener("drop", ondrop);
    spanAttaccanti.setAttribute("draggable", true);
    spanAttaccanti.setAttribute("id", arrAttccanti[0][i]);
    spanAttaccanti.innerHTML = arrAttccanti[0][i];
    divAttacco2.appendChild(spanAttaccanti);

and this is the event.

<sup>let dragedItem   

function onDragStart(event){
  console.log("inizio")
  setTimeout(()=>this.classList.add("hidden"),0)
   dragedItem=this
  
}
function dragEnd(event) { 
  dragedItem=null
}
function ondragover(e) {
  console.log("hover");
  
  e.preventDefault()
}
function onDrop(event) {
  console.log("drop");
  event.preventDefault();
}</sup>

the proble is that the event onDrop never fire.
my Console

please help

I’ m a noob of js and i’m starting to learning this langauage

How can I change the color of a button and display text based on a form submission? (JavaScript/HTML beginner question)

Javascript beginner mistakes(?). Behavior expected seems to be buggy

I’m trying to create a simple website with a form submission that will make the submit button green if the answer is right and red otherwise. there should also be a text that appears below as “Correct!” or “Wrong”

Here is the code

HTML:

    <body>
        <div class="header">
            <h1>Trivia!</h1>
        </div>

        <div class="container">
            <div class="section">
                <h2>Part 1: Multiple Choice </h2>
                <hr>
                <h3>Which one of these languages are not spoken in Europe?</h3>

                <button type="button">French</button>
                <button type="button">Italian</button>
                <button type="button">Korean</button>
                <button type="button">Spanish</button>

                <p></p>

            </div>

            <div class="section">
                <h2>Part 2: Free Response</h2>
                <hr>
                <h3>Which language did French, Italian, Spanish and Portuguese cam from?</h3>
                <form>
                    <input type="text" id="text">
                    <button type="submit" id="submit">Check Answer</button>
                </form>
                <p id="p2"></p>
            </div>
        </div>
    </body>

Javascript:

            document.addEventListener('DOMContentLoaded', function() {



                document.querySelectorAll('button').forEach(function(button) {
                button.addEventListener('click', function() {


                    document.querySelectorAll('button').forEach(function(btn) {
                        btn.style.backgroundColor ='';
                    });

                    //To get the selected answer
                    let selected_answer = button.textContent;

                    //Check if answer is correct
                    if (selected_answer == 'Korean') {

                        button.style.backgroundColor = 'green';

                        //Add result as text
                        document.querySelector('p').innerHTML = 'Correct';
                    } else {
                        //if answer is wrong
                        button.style.backgroundColor = 'red';

                        document.querySelector('p').innerHTML = 'Wrong';
                    }
                });
            });
            });


            document.querySelector('#submit').addEventListener('click', function(event){
                event.preventDefault();

                let answer = document.querySelector('#text').value.toLowerCase();
                let button1 = document.querySelector('#submit');

                if (answer === 'latin') {

                    button1.style.backgroundColor = 'green';
                    document.querySelector('#p2').innerHTML = 'Correct!';
                } else {

                    button1.style.backgroundColor = 'red';
                    document.querySelector('#p2').innerHTML = 'Wrong!';
                }
            });

Once i run it and answer it correctly the text below will say “CORRECT” however

The submit button will turn red and Part 1 will have a result “Wrong”

Why doesn’t const { innerRef, …props } = this.props; grab a refrence to this.props.innerRef in react ref forwarding?

After reading forwarding refs from react legacy docs and following the examples from the SO post on using ref forwarding on classes, I tried to create a working example as following:

class Card extends React.Component {

  constructor(props) {
    super(props);
    this.myRef = React.createRef();
    //after three seconds focus myRef
    setTimeout(() => {
      console.log(this.myRef);
      this.myRef.current.focus();
    }, 3000);
  }

  render() {
    return <FancybtnWthRef ref={this.myRef} txt="random"/>;
  }
}

//Fancybtn class based componenet with ref forwarding

class Fancybtn extends React.Component {
  constructor(props) {
    super(props);
    const { innerRef, ...props2 } = this.props;
    console.log(innerRef, this.props.innerRef); //doesn't get live binding to this.props.innerRef
  }

  render() {
    return (
      <button className="fancy-btn" ref={this.innerRef} {...this.props2}>
        {this.props.txt}
      </button>
    );
  }
}

const FancybtnWthRef = React.forwardRef((props, ref) => {
  return <Fancybtn {...props} innerRef={ref} />;
});




ReactDOM.render(
  <Card />,
  document.getElementById('root')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

<div id="root"></div>

On the other hand, if I grab the this.props.innerRef object directly for button, then it works:

class Card extends React.Component {

  constructor(props) {
    super(props);
    this.myRef = React.createRef();
    //after three seconds focus myRef
    setTimeout(() => {
      console.log(this.myRef);
      this.myRef.current.focus();
    }, 3000);
  }

  render() {
    return <FancybtnWthRef ref={this.myRef} txt="random"/>;
  }
}

//Fancybtn class based componenet with ref forwarding

class Fancybtn extends React.Component {
  constructor(props) {
    super(props);
    const { innerRef, ...props2 } = this.props;
    console.log(innerRef, this.props.innerRef);
  }

  render() {
    return (
      <button className="fancy-btn" ref={this.props.innerRef} {...this.props2}>
        {this.props.txt}
      </button>
    );
  }
}

const FancybtnWthRef = React.forwardRef((props, ref) => {
  return <Fancybtn {...props} innerRef={ref} />;
});





ReactDOM.render(
  <Card />,
  document.getElementById('root')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

<div id="root"></div>

In plain javascript destructuring gets live binding of objects as following:

var obj = {x:1, obj2: {y: 33}}
const {x, obj2} = obj;
obj2.y = 44;
cconsole.log(obj.obj2.y); //gives 44

Using the same argument why doesn’t const { innerRef, ...props } = this.props; grab the actual this.props.innerRef for the button?

HTML page login authenticated against encrypted password in the page

I have a simple html webpage. I wanted to give a few users access to another page on the same site. They all will login with the same password, the page has information that only those group of users should know.
Is it possible to have an encrypted password in the html, which will be decrypted and checked for when users login with the same password I provide them? This will prevent from anyone looking at the html page and using password in plain text.
I do not want to build in a server side authentication, as I want to use only html in AWS amplify. I tried with php scripts but I have to switch from amplify, which I do not want to. I want to keep the whole login screen HTML based.

Finally, I want to display a page with some general information when the user is authenticated.

thanks

Tried php scripts but could not get it to work with lambda on AWS. looking for some help in checking user entered password in the login page with encrypted password stored in html page.

How to Implement a Promise-Based Queue with Task Prioritization in JavaScript?

I am trying to build a promise-based queue in JavaScript where each task returns a promise that resolves when the task is done. The queue should process tasks one at a time, waiting for each promise to resolve before starting the next.

However, there is a complexity: each task has a priority, and higher-priority tasks should jump the queue. If a higher-priority task is added, it should be the next task to run after the currently-running task completes, regardless of its position in the queue.

Here’s a simplified example:

class Task {
  constructor(fn, priority) {
    this.fn = fn;
    this.priority = priority;
  }
}

class PriorityPromiseQueue {
  // implementation needed
}

The PriorityPromiseQueue should process Task objects, calling each Task.fn function in priority order. Task.fn will return a promise.

Does anyone have suggestions on how to implement this PriorityPromiseQueue? I’ve considered using an array and keeping it sorted by priority, but I’m wondering if there’s a more efficient way, especially for large numbers of tasks.

Error in fetching all task from mongoDB Database

I am not able to find exactly what the error. I am fetching all the tasks from database. Initially it gives all task but after deleting 1 task i am getting this error . how to resolve this ?

/**
 * Route : /api/v1/task/fetch-task
 *
 */
const fetchTask = async (req, res) => {
  try {
    const tasks = await taskModel.find();
    console.log(tasks);
    if (tasks.length === 0) {
      return res.status(404).json({
        success: false,
        message: "No Task Found",
      });
    }

    res.status(200).json({
      success: true,
      data: tasks,
    });
  } catch (error) {
    res.status(400).json({
      success: false,
      message: error.message,
    });
  }
};

Error Image :
enter image description here

I tried the above mention code .

Concatenating a string to an iframe url causes it to not work. Any solutions?

I’m trying to concatenate a string into the URL of an iframe but it doesn’t work when I do this. Below is my function. Help is greatly appreciated.

function map (loc) {
return (

    <div align="center">
        <iframe 
            width="300" 
            height="170" 
            src={`https://maps.google.com/maps?q=獸醫+${loc}&hl=zh-TW&z=12&amp;output=embed`}
            >
        </iframe>
    </div>
);

}

I tried other concatenating formats and it still didn’t work. There aren’t any error messages either.

React not triggering JSX code after state update

I have a React Functional component

const [isNewButtonClicked, setIsNewButtonClicked] = useState(false);

There is a custom Button component as below

<Button onClick={addRecord}>Add New Record</Button>

Below is addRecord

const addRecord = (event) => {
        setIsNewButtonClicked(true);
}

In the JSX, I have

{
isNewButtonClicked && <MyField key={someKey} />
}

For some reason, the above JSX code does not get invoked when the button is clicked, even though I am updating the state isNewButtonClicked from false to true.

Is the above way of invoking/rendering JSX code on click of button not correct ?

How to make Tippy.js use existing element

I am writing an app where I use Tippy.js to create popups. My HTML code looks like this:

<popup-target popup-id="1">...</popup-target>
...
<popup-content popup-id="1">
    <!-- This content is live -->
</popup-content>

To initialize Tippy.js, I use the following code:

tippy(target, 
{
    content(reference) { return document.querySelector("popup-content[popup-id="" + identity + ""]").innerHTML; },
...
}

As you can see, I retrieve the innerHTML of the popup-content element. This means that any updates made to the popup-content element will not affect the popup. I would like to set up Tippy.js so that it positions the <popup-content ..> without detaching it from the DOM.

Unable to upload files from local system in puppeteer using browser stack. How to fix this?

I am using browser stack local to run my puppeteer scripts. I have browserstack.local set to true in my capabilities list and I have a secure tunnel created between browser stack and my local system. But I am not able to upload a file that is in my project repository. Browser stack is not reading this file. Please help me to solve this issue. How can I upload a file present on my system in my script?

I tried to upload file to browser stack’s files and media. But could not figure out where my file is stored.

loading animation not showing

HTML:

<!DOCTYPE html>
<html lang="en">
    <head>
        <link href="loading.css" rel="stylesheet"/>

        <script type="text/javascript">
            async function refreshStatus()
            {
                document.getElementById("loading-overlay").display = "flex";
                document.getElementById("loader").display = "block";
                alert("trying");
                try
                {
                    await new Promise(r => setTimeout(r, 2000));
                    var response = await fetch(
                        the_url,
                        {
                            method: 'POST',
                            headers: {
                                        'Accept': 'application/json',
                                        'Content-Type': 'application/json',
                                        'Access-Control-Allow-Origin': '*',
                                    },
                            body: JSON.stringify({"ok": "yes"})
                        }
                    );
                }
                catch (_error)
                {
                    document.getElementById("error-div").display = "flex";
                    document.getElementById("error-div").innerHTML = _error.message;
                    return;
                }
            }
        </script>

    </head>
    <body>
    <div id="loading-overlay">
        <div id="loader"></div>
        <p id="error-div"></p>
    </div>
    <button type="button" id="button_queue_go" onclick="refreshStatus();">Show Status</button>
    </body>
</html>

loading.css

#loading-overlay {
  z-index: 10;
  display: none;
}
.loader {
  border: 16px solid #f3f3f3;
  border-top: 16px solid #3498db;
  border-radius: 50%;
  width: 120px;
  height: 120px;
  animation: spin 2s linear infinite;
}
#error-div {
  z-index: 20;
  display: none;
}

When I click on the button, I see the alert, but during the await new Promise(r => setTimeout(r, 2000)); I dont see the loading animation.

Custom Cursor Smooth Transition

I would be really happy if someone can help me!

I’m facing an issue that I’ve been trying to resolve but haven’t found a satisfactory solution yet. I’m seeking assistance from someone more knowledgeable.

My objective is to use a custom cursor that is simply a 20px by 20px black dot. I have attempted two approaches so far:

Initially, I tried using an element to represent the custom cursor and control its behavior. This method has worked for me in the past, but I’m currently working with a draggable Swiper slider. Unfortunately, when dragging, the custom cursor jumps to the previous slide.

As an alternative, I attempted to use the ‘cursor: url(“image”)’ CSS property. While this approach technically works, it lacks the option to scale the cursor. To work around this limitation, I change the image on hover to a larger dot. However, this transition is not smooth at all.

If anyone could offer their assistance and guidance, I would be immensely grateful. Thank you in advance.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chatapplication/com.example.chatapplication.MainActivity}:

I was creating a messaging app the Haxm was not downloaded
when I Downloaded from a Github link the flamingo software started to crash
then I deleted the Haxm and tried to run in my phone but launch was successful but app is not opening it says there is a bug Iam new to android studio and I don’t know where to look for bugs in my code because my debugger was clean when I saw my logcat it showed the following error
: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chatapplication/com.example.chatapplication.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

package com.example.chatapplication

import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText



private lateinit var editemail:EditText
private lateinit var editpassword:EditText
private lateinit var btn:Button
private lateinit var btn2:Button





class MainActivity : AppCompatActivity() {

    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        editemail=findViewById(R.id.email)
        editpassword=findViewById(R.id.password)
        btn=findViewById(R.id.button)
        btn2=findViewById(R.id.button2)
        btn2.setOnClickListener {
            val intent=Intent(this,Signup::class.java) //signup activity is empty xml and java file
            startActivity(intent)
        }


    }
}

activity_main.xml


`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relative"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    >

    <ImageView
        android:id="@+id/logo"
        android:layout_width="200dp"
        android:layout_height="182dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="113dp"
        android:layout_marginTop="26dp"
        android:background="@drawable/logo" />

    <EditText
        android:id="@+id/email"
        android:layout_width="405dp"
        android:layout_height="48dp"
        android:layout_below="@+id/logo"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="6dp"
        android:layout_marginLeft="6dp"
        android:layout_marginTop="28dp"
        android:layout_marginEnd="0dp"
        android:layout_marginRight="6dp"
        android:background="@drawable/border"
        android:hint="Email"
        android:paddingLeft="15dp" />

    <EditText
        android:id="@+id/password"
        android:layout_width="405dp"
        android:layout_height="48dp"
        android:layout_below="@+id/relative"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"
        android:layout_centerInParent="true"
        android:layout_marginStart="4dp"
        android:layout_marginLeft="6dp"
        android:layout_marginTop="33dp"
        android:layout_marginEnd="2dp"
        android:layout_marginRight="6dp"
        android:background="@drawable/border"
        android:hint="Password"
        android:paddingLeft="15dp"
        tools:ignore="NotSibling" />


    <Button
        android:id="@+id/button2"
        android:layout_width="140dp"
        android:layout_height="wrap_content"


        android:layout_alignParentTop="true"

        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="497dp"
        android:layout_marginEnd="116dp"
        android:layout_marginBottom="186dp"
        android:background="@drawable/fill"
        android:text="signup" />

    <Button
        android:id="@+id/button"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="424dp"
        android:layout_marginEnd="161dp"
        android:layout_marginBottom="224dp"
        android:background="@drawable/fill"
        android:text="Signin" />


</RelativeLayout>
`