Is there a way to display: none; all but one element using if statement?

Trying to hide all but one product card so that the one displayed product card can be turned into a carousel to display the hidden product cards when carousel buttons are clicked.

Product cards will only be hidden when screen size is less that 600px (see media queries)

Javascript

let productIndex = document.getElementsByClassName("product-card")[0];
let productCard = document.getElementsByClassName("product-card");


if (productCard !== productIndex) {
productCard.style.display = "none";
}

The above code block will not hide the product cards but

if (productCard !== productIndex) {
productIndex.style.display = "none";
}

will hide the first the product.

jsfiddle available here

Sort Array Based on Another Array’s Sorting

I have two arrays:

arr1 = [4,2,3,5,1]
arr2 = ['a','b','c','d','e']

And if I apply an sorting algorithm to arr1, (e.g. by smaller number) it should update the indexes in the same way on arr2 (if arr1’s 4, before in index 0 gets moved to index 3, arr2’s value in index 0 gets moved to index 3).

ex.

arr1 = [1,2,3,4,5]
arr2 = ['e','b','c','a','d']

I’ve tried working with the JS sort function to no avail. Because the numbers in the arrays may be duplicates, indexOf() doesn’t work. I don’t feel I need to implement my own sorting algorithm because I really feel like an elegant way is possible here.

ExpressJS res.sendFile causes server to crash on client abort

Learning NodeJS/ExpressJS here. Below is an example of my extremely simple ExpressJS GET request that is supposed to return a JSON file.

app.get("/getFile", async (req, res) => {
  if (res.headersSent) return;

  try {
    res.sendFile(
      path.join(__dirname, "latest-data", "my-file.json"),
      (err) => {
        if (err) {
          res.status(500).send("Internal Server Error");
        }
      }
    );
  } catch (error) {
    console.error(error.stack);
  }
});

While 99.9% of the time the request works as intended. However when stress testing with Apache JMeter to test 1000 concurrent users performing the request, I noticed that when I abort the request, the following error appears and my server process ends.

node:_http_outgoing:603
    throw new ERR_HTTP_HEADERS_SENT('set');
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:387:5)
    at ServerResponse.setHeader (node:_http_outgoing:603:11)
    at ServerResponse.header (C:UsersUSERDesktopmy-projectmy-project-servernode_modulesexpresslibresponse.js:794:10)
    at ServerResponse.send (C:UsersUSERDesktopmy-projectmy-project-servernode_modulesexpresslibresponse.js:174:12)
    at C:UsersUSERDesktopmy-projectmy-project-serverindex.js:113:27
    at C:UsersUSERDesktopmy-projectmy-project-servernode_modulesexpresslibresponse.js:450:22
    at onaborted (C:UsersUSERDesktopmy-projectmy-project-servernode_modulesexpresslibresponse.js:1054:5)
    at onfinish (C:UsersUSERDesktopmy-projectmy-project-servernode_modulesexpresslibresponse.js:1088:50)
    at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
    at listener (C:UsersUSERDesktopmy-projectmy-project-servernode_moduleson-finishedindex.js:170:15) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

Now I can tell that it’s something to do with the server trying to send a response more than once, however I cannot seem to understand or figure a way how to avoid or use a try catch statement to avoid my server from crashing. This is an issue that will happen when the server traffic gets heavy, I would like to be able to bypass this.

By applying the following logic at the start if (res.headersSent) return; I would assume that it would work but it did not.

ExtJS – sliding menu after clicking on the table header

I am currently working on a project that uses ExtJS. Unfortunately I have never worked with it so it is difficult for me to debug. I would like to find the code that is responsible for this howling menu like in the picture below. When I hover over the header in the table with the cursor, it displays a down arrow that can be clicked and then this menu appears.

menu

Unfortunately, I completely do not know how to find this and where someone called it up in my porojekt, it is so complicated that it is difficult to find. I’m very sorry for the scarcity of information, but maybe someone can guide me with some keywords, code structures or things that definitely appear I should be looking for? Debugger onClick event stops in ext-all.js in the onDelegatedEvent function, but I don’t know at all what happens before that. I will be happy to answer your questions so that you can better understand my problem

Is there a faster way for me to make my website?

certainly, there are web apps that help you create a website with just some clicks of a button. But I’m talking about some tools like Google Inspect tool that helps you identify the sizes of paddings, and margins of your elements and position them to you’re liking. –but better –and also faster.

I use Google Inspect and is very useful. Most of the time, I use it to correct my syntax but it’s taking a lot of my time.

Can’t delete from table and database

I’m trying to remove data from table and database but the output always shows the error in the if else statement and the delete function is not working I hope you can help me fix this

Here is the code:

javascript

function remove_book_log(log_id)
{
  if(confirm("Are you sure, you want to remove this booking?"))
  {
    let data = new FormData();
    data.append('log_id',log_id);
    data.append('remove_book_log','');

    let xhr = new XMLHttpRequest();
    xhr.open("POST","ajax/appointment_logs.php",true);

    xhr.onload = function()
    {
      if(this.responseText == 1){
        alert('success','Booking Removed!');
        get_book_log();
      }
      else{
        alert('error','Removal failed!');
      }
    }
    xhr.send(data);
  }
}

Here is the php code:

  if(isset($_POST['remove_book_log']))
  {
    
    $frm_data = filteration($_POST);

    $res = delete("DELETE FROM `bookings_logs` WHERE `sr_no`=?",[$frm_data['log_id'],0],'ii');

    if($res){
      echo 1;
    }
    else{
      echo 0;
    }

  }

The output always shows ‘Removal failed!’

How to solve this problem? PHP Fatal error: Call to a member function find() on bool in /htdocs/seo/core

My website running a SEO score checking system and there’s a website reviewer to check your website SEO score, but, I am getting this error on Line 299 of my code, however the function of this line is executed correctly and it does what I expect it to do. It work with some websites and also don’t working with some websites:

here’s the fatal message (Fatal error: Uncaught Error: Call to a member function find() on bool in /htdocs/seo/core/controllers/domains.php:299 Stack trace: #0 /htdocs/seo/core/app.php(162): require() #1 /htdocs/seo/index.php(25): require(‘/htdocs/seo/cor…’) #2 {main} thrown in /htdocs/seo/core/controllers/domains.php on line 299)

and here’s the code of domains.php:

if(isset($_POST['image'])){
    
    //Image without "alt" tag
    $imageCount = 0;
    $imageWithOutAltTag = 0;
    $hideClass = $imageWithOutAltTagData = '';
    $imageMsg = $lang['CS970'];
    $imgArr = array();
    
    foreach($domData->find('img') as $imgData){
        if(Trim($imgData->getAttribute('src')) != ""){
            //Valid Image
            $imageCount++;
            if(Trim($imgData->getAttribute('alt')) == ""){
                //Without "alt" tag!
                if($imageWithOutAltTag == 3)
                    $hideClass = 'hideTr hideTr2';
                $imageWithOutAltTagData .= '<tr class="'.$hideClass.'"> <td>'.Trim($imgData->getAttribute('src')).'</td> </tr>';
                $imgArr[] = Trim($imgData->getAttribute('src'));
                $imageWithOutAltTag++;

PS: the line 299 is ( foreach($domData->find(‘img’) as $imgData){ )

and here’s the code of app.php:

if(PLUG_SYS)
    require LIB_DIR.'user_level1.php';

$path = CON_DIR . $controller . '.php';
    if(file_exists($path)){
        require($path);
    } else {
        writeLog('Controller File ("'.$controller.'.php") Not Found');
        $controller = CON_ERR;
        require(CON_DIR. $controller . '.php');```

PS: the line 162 is  ( require($path);  )

I've tried to delete some coding that I've added to the website recently but still shows the same error.

Override HTML email validation error message styling

https://bookmark-landing-page-psi-fawn.vercel.app/

If you go to the bottom of the page there is an email textbox with a submit button. When you submit an invalid email, it gives a custom message ‘Whoops, you entered an invalid email’ etc with custom styling.

I know about the :invalid selector but this isn’t that. How did this person accomplish this?

Right now I get the ‘Please enter a valid email’ message with a little white dialog box. This is the behavior I want to overwrite

How to Prevent Page Refresh on Button Click When Submitting Data with JavaScript

I am working on a web application where a button click triggers an async function to submit data. However, the page refreshes every time I click the button, even though I have used e.preventDefault(). Below is a minimal representation of my code.

JavaScript Code:

document.addEventListener('DOMContentLoaded', () => {
    const downloadButton = document.getElementById('downloadButton');
    downloadButton.addEventListener('click', e => download(e));
});

async function download(e) {
    e.preventDefault(); // Prevent default button click action

    const videoUrl = document.getElementById('videoUrl').value;
    console.log('Downloading video from:', videoUrl);

HTML Snippet:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Button Click Test</title>
</head>
<body>
    <input id="videoUrl" type="text" placeholder="Enter Video URL">
    <button type="button" id="downloadButton">Download</button>

    <script src="script.js"></script>
</body>
</html>

Issue:

When the button is clicked, the page still refreshes despite using e.preventDefault() in the download function. The expected behavior is for the page to not refresh and for the data to be sent to the server asynchronously.

Attempts to Resolve:

  1. Ensured e.preventDefault() is used in the event handler.
  2. Verified that the button type is "button" to prevent default form submission.
  3. Checked for JavaScript errors in the console (none found).
  4. Ensured the event object e is passed correctly to the download function.

Question:

What could be causing the page to refresh even after using e.preventDefault()? Is there a part of my setup or code that I might be overlooking?

Additional Context:

  • I’m testing this in modern browsers (Chrome, Firefox).
  • The script is included correctly in the HTML and is executed after the DOM is fully loaded.

Why I can’t use ‘super’ in prototype method definition when I can use Object.getPrototypeOf(this.constructor.prototype)?

So I tested this code:

class C1 {}

C1.prototype. f =function(){ return 1 }

class C2 extends C1 {}

C2.prototype. f =function(){ return super.f()+1 }

And it throws a syntax error: ‘super’ keyword unexpected here.

But if I do:

C2.prototype. f =function(){ return Object.getPrototypeOf(this.constructor.prototype).f() + 1 }

It does return a two!

So does anyone know why ‘super’ doesn’t work? I see no reason for it.

Thanks!

Do Javascript have touch.event? [closed]

object.onclick = function(e) {
  e = e || window.event;
  var target = e.target || e.srcElement;
  alert(target);
}

It have window.event, does it have touch.event for smartphones like this one down here?

object.onclick = function(e) {
  e = e || touch.event;
  var target = e.target || e.srcElement;
  alert(target);
}