JavaScript appendChild return null [duplicate]

I’m trying to make a function that switches two divs. Another function adds the first div to where the second div is located and vice-versa. I’m using React and JS.
enter image description here

java.js (functions)

const switchCol = document.querySelectorAll("div");
const ab = document.getElementById("switch_id");
const a = document.getElementById("switchB");
const b = document.getElementById("switchA");

if(ab) {
    ab.addEventListener("click", switchColumns, false);
    a.addEventListener("click", switchA, false);
    a.addEventListener("click", switchB, false);
}

switchCol.forEach(switches => switches.addEventListener('click', switchColumns));
switchCol.forEach(switches => switches.addEventListener('click', switchA));
switchCol.forEach(switches => switches.addEventListener('click', switchB));

const col1 = document.getElementById('column1_id');
const col2 = document.getElementById('column2_id');
const cols1 = document.getElementById('column_one');
const cols2 = document.getElementById('column_two');

let col11 = document.getElementsByClassName('column1');
const col12 = document.getElementsByClassName('column2');
const cols = document.getElementsByClassName('columns');

//switch both divs
function switchColumns(){
    for (let i = 0; i < cols.length; i++){
        col11[i].append(col2);
        col12[i].append(col1);
    }
}

//add div A to div B
function switchA(){
    col12.append(col1);
}

//add div B to div A
function switchB(){
    col11.append(col2);
}

index.js

import "../style.css";
import "./java.js"

class index extends React.Component {
    render()
    {
        return (
            <div className="container">
                <div className="columns" id="columnsToSwitch">
                    <div className="column_one">
                        <div className="column1" id="column1_id">
                            <p>Column1</p>
                        </div>
                        <div className="switchToB" id="switchB">Switch to B</div>
                    </div>
                    <div className="column_two">
                        <div className="column2" id="column2_id">
                            <p>Column 2</p>
                        </div>
                        <div className="switchToA" id="switchA">Switch to A</div>
                    </div>
                </div>
                <div className="switch" id="switch_id">Switch</div>
                <script src="./java.js"/>
            </div>
        );
    }
}

export default index;

When I click on any of the options, this is what I get.
enter image description here

The errors that output after clicking the options
enter image description here

DataTables displaying blank cells but the rows have data

I am having a problem with the DataTables plug-in for jQuery.
I am loading data with a JSON, but only some columns get their values displayed (see screenshot below).

No values being displayed for the three right columns

However, I printed the selected row from Datatables with console.log(table.row(this).data()) and the print shows that there is data for the columns that appear to hold no data. Furthermore, right I am setting the "defaultContent": "", but if I set it as "defaultContent": "Not set", DataTables displays “Not set” for all those blank values, which is expected, but means that somehow it is not reading the content from the rows. Please check the next screenshot with the console print with data on columns “Un.”, “Quant.”, “Total [€]”.

Console print on the client showing that the row holds data for the columns that appear blank on the table

Has anyone gone through this?

angular javascript document and window functions best practice

In angular component.ts I use ngOnInit function to implement Javascript document and window functions.

for example :

ngOnInit(): void {
  document.addEventListener('mouseup', () => {
    this.isRatingPopupActive = false;
  });
}

this is part of my code to close opened popup after mouseup similar to facebook like button .. is this right?

and if it is wrong to use onInit this way, what is the best practice then?

thank you all <3

click submit button every 4 secconds

how can i make automatic click per each 4 sec ?

i want that submit button be clicked every 4 sec.
but its not work correctly

my works :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>*BruteForce*</title>
    <script src="!Needs/jquery.min.js"></script>
    <style>
        #form {
            margin: 0 auto;
            text-align: center;
        }

        #getHash {
            width: 440px;
            text-align: center;
        }

        #length {
            text-align: center;
        }

        #boxContent {
            width: 833px;
            height: 469px;
            border: 1pt solid black;
            text-align: left;
            margin: 0 auto;
        }
    </style>
</head>
<body>
<form id="form" method="post" action="server.php">
    <span>Enter Your Hash (SHA256) : </span>
    <input id="getHash" type="text" value="" name="getHash" title="">
    <input id="length" type="number" value="" name="length" placeholder="Enter the Length">
    <input id="create" type="submit" value="create" title=""><br><br>

    <div id="boxContent"></div>
    <input id="btn" type="button" value="..." title=""><br><br>
</form>
<script>

    setInterval(function () {
        $("#create").click(function () {
            event.preventDefault();
            $("#boxContent").html(("Loading ..."));
            $.ajax({
                type: 'POST',
                url: "server.php",
                data: $("#form").serialize(),
                success: function (response) {
                    $("#boxContent").html((response));
                }
            });
        });
    }, 4000);


</script>
</body>
</html>

      

here is php :

<?php
$getHash = $_POST['getHash'];
$length = $_POST['length'];

function randGenerator()
{
    $length = "10";
    $characters = "0123456789abcdefghijklmnopqrstuvwxyz!@#";
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;

}

function crack()
{
    global $getHash, $length;
    for ($i = 1; $i <= $length; $i++) {
        $text = randGenerator();
        $beHash = hash('sha256', $text);
        if ($beHash == $getHash) {
            echo "<span class='true'>" . $text . "</span>";
            echo "<br>";

        } else {
            echo "<span class='false'>" . $text . "</span>";
            echo "<br>";

        }
    }
}

crack();

as you can see . im trying to make simple brutforce method
but its manual , i want to create a auto .
i used setinterval for every 4 sec . but it doesnt work . ? any idea?

How can I make only a certain part of a label clickable?

I’m working on a project and I have an accordion list with input checkbox and labels. The problem is, the label makes larger when I click it, revealing the content inside it, but when I click the content, the label checks the input, hiding the content inside the label, so, my idea was that only a certain part of the label (4em), can be clickable to activate the input checkbox, and the rest was only clickable for the objects inside it, without activating the input checkbox.

For a better idea here’s my code:

<input id="season1" type="checkbox">
<label class="ls1" for="season1">
    <h3 class="first">Season 1</h3>
    <i class="fas fa-angle-right"></i>
    <div class="episodes1-grid">
    </div>
</label>

input[type="checkbox"] {
    display: none;
}

label {
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    height: 4em;
    transition: height 0.8s ease-in-out;
}

Maybe this doesn’t even require the use of javascript and it’s my problem in the use of a label in the first place.

Basic Automated Test of a Javascript Browser Library

I am using Webpack to build a webapp that is designed for the browser.

After my build process I have two files: index.html and app.bundle.js

To my dismay I have found that the although the development Webpack configuration works the production configuration does not because of errors during minification.

I am looking for the most basic way to run a test that does the following:

  • Opens the index.html file (which contains <script defer="defer" src="app.bundle.js"> and sees if there are any errors when the script contained in app.bundle.js runs

That is it.

I need a full Browser environment (requestianimationframe, fetch, etc.)

I have tried JSDOM and I get Error: Uncaught [ReferenceError: fetch is not defined] which looks like it has a bunch of issues, and then there are a tremendous amount of overlapping libraries and tools like Phantom.js Zombie.js Pupeteer, headless-chrome etc. and I honestly can’t figure out how to just open my app. I have tried to explore all of these tools but they are all complicated.

Ideally I wouldn’t have to create a local webserver, but I’d be fine with that if this is what is required.

How To Replace Items in Second Array Using React Post Api

I have a post Api in which I want to send the answers based on users input in an array like :
userAnswer{“correct”, “correct”, “wrong”, “notAttempted”, “correct”} and then replace the correct and wrong answers based on their index in the next section in a different array that is like this :

{
“answersArray”: [
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”,
“notAttempted”
],
}

  const [arry, setArry] = useState([]);

  const nextQuestion = (examData) => {

    if (studentAnswered == examData[currentQuestion].correct) {
      setArry((prevState) => [...arry, "correct"]);
    } else if (studentAnswered == null) {
      setArry((prevState) => [...arry, "notAttempted"]);
    } else {
      setArry((prevState) => [...arry, "wrong"]);
    }

    setCurrentQuestion(currentQuestion + 1);
    setStudentAnswered(null);
  };

The array is a useState Function and NextQuestion is an onClick function it adds the selected answer to the array onClick or keeps the value null if no options are selected. **I was able to do most of the work. Now I just need to update the correct and wrong answers to the AnswersArray Above based on their indexes. Thanks **

How to add a variable to this kind of Regex statement

I am trying to insert a variable into a regex statement
However for some reason
all the methods I found didnt work with this particular statement

This code works perfectly fine and return true

const regex = /byoub/i;
const str = 'How are you today?';
console.log(regex.test(str));


const strInsert = "you"
const regex = new RegExp(`/{strInsert}b/i`);
const str = 'How are you today?';
console.log(regex.test(str));

I attempted to do the following
However this resulted in an output of false when it should be true

How do I span css formatted text over fixed sized divs

I’m creating an online screenwriting program using HTML and CSS. The format of screenplays consists of scene headings, dialogs, and action elements. Each element is in a DIV with its own set of css rules (left and right padding and margins are the real differences). The formatting of the script is great. But now, I need to put the formatted text into pages. Meaning, once the formatted text reaches the bottom of the 8.5in x 11in DIV, it needs to be cut off and continue into the next div. Initially I was thinking I’d have to calculate the width and height of each different inner div element and then truncate when appropriate. Wonder if there’s an easier way. I’m also using Smarty templates. I’ve attached a photo for referencesample script

I would like to add a click eventlistener on each row elements of the table

I created a 3×3 table for my tic-tac-toe game using the table tag and i added a click event listener to the each of the row using forEach loop but unfortunately nothing is showing in my console

const boxes = document.querySelectorAll('.box');
const strategy = document.querySelector('#strategy');
const restartBtn = document.querySelector('#restart');
const arry = [];
const tick_x = 'X';
const tick_o = 'O';
const userAction = () => {
  boxes.forEach((box) => {
    box.addEventListener('click', function clk() {
      console.log("clicked")
    })
  })
}
html {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  background-color: teal;
  overflow: hidden;
  font-family: "Itim", cursive;
}

.game {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

p {
  color: white;
  text-align: center;
  margin: 40px auto;
  width: 200px;
}

table {
  margin-bottom: 50px;
  border-radius: 10px;
  border-top: 2px solid white;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  border-right: 2px solid white;
}

button {
  width: 100px;
}

h1 {
  width: 100%;
  height: 100%;
  text-align: center;
}

.row1 td {
  width: 100px;
  height: 100px;
  border-bottom: 1px solid white;
  border-left: 1px solid white;
}

.row2 td {
  width: 100px;
  height: 100px;
  border-bottom: 1px solid white;
  border-left: 1px solid white;
}

.row3 td {
  width: 100px;
  height: 100px;
  border-left: 1px solid white;
}

.r11 {
  border-left: none;
}
<div class="intro">
  <p class="name">TIC-TAC-TOE</p>
  <h2 id="strategy"></h2>
  <p class="player">Player X'S turn</p>
</div>
<table>
  <tr class="row1">
    <td class="r11">
      <h1 class="box" id="0"> </h1>
    </td>
    <td class="r12">
      <h1 class="box" id="1"> </h1>
    </td>
    <td class="r13">
      <h1 class="box" id="2"> </h1>
    </td>
  </tr>
  <tr class="row2">
    <td class="r21">
      <h1 class="box" id="3"> </h1>
    </td>
    <td class="r22">
      <h1 class="box" id="4"> </h1>
    </td>
    <td class="r23">
      <h1 class="box" id="5"> </h1>
    </td>
  </tr>
  <tr class="row3">
    <td class="r31">
      <h1 class="box" id="6"> </h1>
    </td>
    <td class="r32">
      <h1 class="box" id="7"> </h1>
    </td>
    <td class="r33">
      <h1 class="box" id="8"> </h1>
    </td>
  </tr>
</table>
<button id="restart"><h3>Reset</h3></button>
</div>

How do you go to another page on button click in react?

FYI I’m learning reactjs.
I have a quick question. I am developing a restaurant website and I want to make my “View Full Menu” button on my homepage(Home.js) take me to my menu.js file. I was able to redirect to the menu page on my App.js file, which is essentially where I have my functional navbar components. Please let me know if I need to show more code for this question.
Also, I know that I probably have to use “onClick” on the button, but after doing some research, I cannot figure out how to go to the menu.js page. Thank you in advance.

            <div>
                <Card className="text-center">
                    <Card.Header>Featured</Card.Header>
                    
                    <Card.Body>
                        <Card.Title>Menu</Card.Title>
                        <Card.Text>
                            orem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. At consectetur lorem donec massa sapien. Euismod lacinia at quis risus sed vulputate odio ut.
                        </Card.Text>
                        <Button variant="primary">View Full Menu</Button>
                    </Card.Body>
                    <Card.Footer className="text-muted"></Card.Footer>
                </Card>
            </div>

Here is my working “menu” button on my App.js file.

function App () {
  return (
    
    <BrowserRouter>
    <div className="App">
      <Navigation />
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/about" element={<About />} />
        <Route path="/menu" element={<MenuApp />} />
        <Route path= "/fire" element={<Fire />}/>
      </Routes>
    </div>
  </BrowserRouter>
  
  
  );
}

Change a form action based on form input selected

so I have a project that I’m working on.. When I have a certain drop down option or radio button selected, I want the form to redirect to unqualified.html.. Otherwise, I want the form to redirect to qualified.html. I mostly do work in Java, so wrapping my head around JavaScript has been a challenge.. I’m not allowed to use any libraries or jquery for this project.

Here’s my form:

<form method="post" id="linkId" onClick="reDirect()" action=''>
        <div class ="formContent">
            <label for="email"><b>Business Email</b></label><br>
            <input type="email" class="tArea" placeholder="Enter your business email" style="width:350px;" formaction="qualified.html" required><br>
        </div>
        <div class="formContent">
            <label for="businessSize" style="padding-top: 5%;"><b>Business Size</b></label><br>
            <select class="tArea" id="selectbox" style="width:359px;" required>
                <option value ="" disabled selected hidden>Select Size</option>
                <option value="1-10" id="unqualified1">1-10</option>
                <option value="11-50">11-50</option>
                <option value="51-100">51-100</option>
                <option value="101-250">101-250</option>
                <option value="250-1000">250-1000</option>
                <option value="1000+">1000+</option>
            </select>
        </div>
        <div class="paddedContent">
            What is the most important thing to you in a solution?
        </div>
        <div class="radioForms">
                    <input type="radio" name="radBtn" required><label>Real-time Analytics</label>
                    <input type="radio" name="radBtn" class="rightRadio1" id="unqualified2"><label>Scalability</label><br>
                    <input type="radio" name="radBtn"><label>Query Response Time</label>
                    <input type="radio" name="radBtn"><label>Document Storage</label><br>
                    <input type="radio" name="radBtn"><label>High concurrency</label>
                    <input type="radio" name="radBtn" class="rightRadio2" id="unqualified3"><label>Full Text Search</label><br>
                    <input type="radio" name="radBtn"><label>Fast Data Digest</label>
                    <input type="radio" name="radBtn" class="rightRadio3" id="unqualified4"><label>Price</label><br>
                    <br>
                    <input type="submit" class="submitBtn" value="Continue to Schedule a Time ➟">
        </div>
    </form>

And here’s my reDirect() method:

    function reDirect()
    {
        if(document.getElementyById('unqualified1').clicked)
            document.getElementById('linkId').action = "unqualified.html";
        else if (document.getElementyById('unqualified2').checked)
            document.getElementById('linkId').action = "unqualified.html";
        else if (document.getElementyById('unqualified3').checked)
            document.getElementById('linkId').action = "unqualified.html";
        else if (document.getElementyById('unqualified4').checked)
            document.getElementById('linkId').action = "unqualified.html";
        else
            document.getElementById('linkId').href = "qualified.html";
    }

Whenever an input within the form is selected with the id=”unqualified1″, id=”unqualified2″, id=”unqualified3″, or id=”unqualified4″ I want the form to direct users to “unqualified.html” when submitted, otherwise I want it to direct users to “qualified.html”

If anyone has any helpful tips or can see where I’m going wrong with this, I’d greatly appreciate it.

Display blob image from DB to Reactjs

i’m using Springboot, MySQL and ReactJS for this. I’m trying to create a second hand marketplace where users can place ads etc.

At the moment a use can create an add and also add images associated with it, these images get stored in MySQL as a BLOB type.

I have functionality to create an advert and when a user selects an image to upload, the previewed images is displayed on the screen using URL.createObjectURL(), i’m unsure how to do this so that it displays the images associated with the advert (how to get the url like this) from the database.

blob:http://localhost:3000/16d55ccc-15eb-44fd-b0c2-e8f508209e37

What i’d like is that when a user clicks an advert, it loads the blobs/images from the database as images and displays on the client UI.

This is the table with fields that stores images

This is the response im getting (Ad info + image that were added which is the fileUploads field)

javascript format for function using switchVisible on many id’s [duplicate]

I am hiding and showing DIVS with unique IDs. I have many on each of my pages.

script

function switchVisible() {
            if (document.getElementById('taskBox8')) {

                if (document.getElementById('taskBox8').style.display == 'none') {
                    document.getElementById('taskBox8').style.display = 'block';
                    document.getElementById('eol').style.display = 'none';
                }
                else {
                    document.getElementById('taskBox8').style.display = 'none';
                    document.getElementById('eol').style.display = 'flex';
                }
            }
}

Is there a way to modify the script to make the 8 a variable so I can just use this code 1 time and point all my IDs to it or do i have to repeat this script over and over for each unique ID!?

I have this working BUT when I click to activate, the first click does nothing then all subsequent clicks work as desired.

<a href="#EOL" onClick="switchVisible();" >EOL </a>

                            <div >
                            <li id="eol">  
                            <?php include "ticket_y.php"; ?>
                            <?php include "ticket_g.php"; ?>               
                            </li>
                            </div>
                            
                            <div class="editBox" id="taskBox8">
                            <?php include "task-panel.php"; ?>
                            </div>