Why is it showing uncaught reference/ function not defined even though i have defined the function

I tried nothing other than checking what I have written is correct syntactically and with the limited knowledge that I have ..It seems fine

let score = {
  win: 0,
  lose: 0,
  tie: 0,
  dis_score: function() {
    document.querySelector('#win_score').innerText = score.win;
    document.querySelector('#lose_score').innerText = score.lose;
    document.querySelector('#tie_score').innerText = score.tie;
  }
};

function showResult(compChoice, finalResult) {
  document.querySelector('.compChoice_dis').innerText = `${compChoice}`;
  document.querySelector('.result_dis').innerText = finalResult;
  dis_score(); //this function is not defined 
}
showResult("win",3)
<span class="compChoice_dis"></span>
<span class="result_dis""></span>
<hr/>
<span id="win_score"></span>
<span id="lose_score"></span>
<span id="tie_score"></span>

defer script works unexpectedly in html

I always thought that using defer script I can avoid declaring it in the end of the file. but why console log returns empty array ? I couldn’t assign any event listener here. Is defer prop useless ?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script defer>
        document.addEventListener('click', (e) => {
            console.log('DOCUMENT CLICK', e);
            e.preventDefault();
        })
        document.querySelectorAll("body *").forEach((element) => {
            element.addEventListener('click', (e) => {
                console.log(e.currentTarget.tagName, 'CAPTURE');
            }, {capture: true})
        });
        document.querySelectorAll("body *").forEach((element) => {
            element.addEventListener('click', (e) => {
                console.log(e.currentTarget.tagName, 'BUBBLE');
            });
        });
        console.log(document.querySelectorAll("body *"))

    </script>
</head>
<body>
<h1><p>
    <div>
        <a href="google.com">TEST TEST TEST</a>
    </div>
    </p></h1>
</body>

</html>

UPD:

I use latest chrome

Vue Router: How to Access and Log Route Parameter in a Component?

The working router:


  {
      path: '/GameView/:collectionName',
      name: 'GameView',
      component: GameView
    },
    {
      path: '/GameView',
      component: GameView
    }

and the script of the component:

//
import { watch } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
watch(
  () => route.params.collectionName,
  (collectionName, previousCollectionName) => {
    console.log('Collection Name:', collectionName)
    // Tutaj możesz dodać kod do załadowania danych na podstawie kolekcji
  }
)

I want to acess the param of the route and console log it.
So if i enter a route http://localhost:5173/gameview/exp1
i want to console log exp1.
So if i enter a route http://localhost:5173/gameview/abc
i want to console.log abc.
But i dont know how to do it. The console is empty and nothing is happening when entering differen URLs.

I tried to follow Vue docs https://router.vuejs.org/guide/essentials/dynamic-matching.html
and the idea of watch comes from there, but still doesnt work.

Aligning subgrid by root grid

I’m trying to get The Boxes to be aligned to the grid root parent.

I tried gridAreas, named grid items, but no luck. When I uncomment #box2, the whole grid falls apart.

Is there a way to have the Boxes align to #box1 grid?

      <Box
        id="box1"
        sx={{
          display: "grid",
          gridTemplateColumns: "[start-col] 1fr [mid-col] 4fr [end-col]",
          gridTemplateRows: "[start-row] 1fr [mid-row] 4fr 1fr [end-row]",
        }}
      >
        {/* <Box display={"grid"}> id="box2" */}
        <Box
          sx={{ gridColumn: "start-col", gridRow: "start-row" }}
          backgroundColor="red"
        >
          test
        </Box>
        <Box
          sx={{ gridColumn: "end-col", gridRow: "mid-row" }}
          backgroundColor="blue"
        >
          test2
        </Box>
        <Box
          sx={{ gridColumn: "mid-col", gridRow: "mid-row" }}
          backgroundColor="green"
        >
          test3
        </Box>
        <Box
          sx={{ gridColumn: "start-col", gridRow: "end-row" }}
          backgroundColor="yellow"
        >
          test4
        </Box>
        {/* </Box> */}
      </Box>

sandbox link

i want to run js file External Scripts( JS, Jquery) Not working in ReactJS [duplicate]

I am creating a web app frontend using ReactJS.

I have downloaded a Template from which is designed using HTML5 CSS Custom JS file and also includes some third party/vendor JS/jQuery carouFredSel, etc

i have problem on react.js when i open the page error give me on console like

 carouFredSel: No element found for "#mission .carousel.main ul".

when the normal html and add my files java script and other file it work correctly.

i think from the react render it render the home after the script done ?
any help on this problem!

How to close a dialog native element on backdrop click [duplicate]

I’m using an HTML dialog element, more info in the mdn documentation, and I would like to close it when the user clicks on the backdrop that is created.

Is there any official solution for this? The documentation says:

When the modal dialog is displayed, it appears above any other dialogs that might be present. Everything outside the modal dialog is inert and interactions outside the dialog are blocked. Notice that when the dialog is open, with the exception of the dialog itself, interaction with the document is not possible; the “Show the dialog” button is mostly obfuscated by the almost opaque backdrop of the dialog and is inert.

I’m also concerned about accessibility. Could I just detect the user clicking on the backdrop and if so, call the close() function? Are there any aspects to keep in mind about screen reader users for example?

Thanks in advance

How do I retrieve multiple foreign tables do display data?

I am trying to retrieve the related data of the orders, customers, and orderItems according to the logged in station owner. The expected display of the data are the order_id, created_at(orders), details of the orderItems such as the corresponding quantity and the name of the type which can be related from the type_id, and the details of the customer

Data definition:

create table
  public.orders (
    order_id uuid not null default gen_random_uuid (),
    created_at timestamp with time zone not null default (now() at time zone 'utc'::text),
    remarks text not null default ''::text,
    water_station_id uuid not null,
    customer_id uuid not null,
    total numeric null,
    constraint orders_pkey primary key (order_id),
    constraint orders_customer_id_fkey foreign key (customer_id) references customers (customer_id) on update cascade on delete restrict,
    constraint orders_station_id_fkey foreign key (station_id) references station (id) on update cascade on delete cascade
  ) tablespace pg_default;


create table
  public.order_items (
    order_items_id uuid not null default gen_random_uuid (),
    quantity numeric not null,
    order_id uuid not null,
    type_id uuid null,
    station_id uuid null,
    constraint order_items_pkey primary key (order_items_id),
    constraint order_items_order_id_fkey foreign key (order_id) references orders (order_id) on update cascade on delete cascade,
    constraint order_items_station_id_fkey foreign key (station_id) references station (id) on update cascade on delete set default,
    constraint order_items_type_id_fkey foreign key (type_id) references type (id) on update restrict on delete restrict
  ) tablespace pg_default;



create table
  public.customers (
    customer_id uuid not null default gen_random_uuid (),
    "firstName" text not null,
    "lastName" text not null,
    contact_no numeric not null,
    delivery_mode text not null,
    address text not null,
    constraint customers_pkey primary key (customer_id),
    constraint customers_contact_no_key unique (contact_no)
  ) tablespace pg_default;

Each station has a user_id which means that they have an account and I am only trying to retrieve the data that is related to the specific station.

The problem here is that I am unable to retrieve the various types and the information of the customer who placed that order.

 const {data, error} = await supabase
        .from('station')
        .select(`id,
            orders(
                *
            ),
            order_items(
                quantity,
                type_id
            )
        `)
        .eq('user_id', session?.user.id )

Saving user’s cookie preference in JavaScript

I have this simple cookies banner that loads google analytics scripts if the user clicks on accept button. Then it remembers the choice for a month and does not show up again. However if the user clicks decline btn it asks him again as soon as the page is reloaded or visits another page on the site.

It would make sense that both user choices are saved for the month, so the user isn’t forced to accept the cookies in the end.

    // COOKIES START
// ---- ---- Const ---- ---- //
const cookiesBox = document.querySelector(".privacy-container"),
  buttons = document.querySelectorAll(".button");
// ---- ---- Show ---- ---- //
const executeCodes = () => {
  if (document.cookie.includes("SlavicMedia")) {
    // If the cookie is already set, no need to show the cookie consent box
    loadGoogleAnalytics();
    return;
  }
  cookiesBox.classList.add("show");
  // ---- ---- Button ---- ---- //
  buttons.forEach((button) => {
    button.addEventListener("click", () => {
      cookiesBox.classList.remove("show");

      // ---- ---- Time ---- ---- //
      if (button.id == "acceptBtn") {
        document.cookie = "cookieBy= SlavicMedia; max-age=" + 60 * 60 * 24 * 30;
        loadGoogleAnalytics();
      }
    });
  });
};

What would the code modification look like to achieve desired functionality?

Thank you for your valuable inputs

Can I Implement a Regular Drop-Down Menu/ Style Inside a MUI Select Component?

I am currently trying to implement the default drop-down menu appearance in my MUI Select Component.

Desired menu:

Desired menu

My Current Select Component:

My Current Select Component

I have tried wrapping my select element tag inside my FormControl component, this was close to what I wanted in terms of appearance, but wasn’t a copy and paste and the functionality of the MUI select ceased to exist.

My Select component:

<Box sx={{ width: 'calc(32.5% - 10px)' }}>
                        <FormControl fullWidth >
                            <InputLabel>Month</InputLabel>
                            <Select
                                id="demo-simple-select"
                                value={month}
                                label="Month"
                                onChange={handleSelectMonth}
                                sx={{
                                    "&:hover:not(.Mui-focused)": {
                                        "&& fieldset": {
                                            borderColor: "#dadce0"
                                        },
                                    },
                                    ".MuiOutlinedInput-notchedOutline": {
                                        borderColor: '#dadce0',
                                    },
                                    '.MuiSvgIcon-root ': {
                                        fill: "#9e9e9e",
                                    }
                                }}
                            >
                                <MenuItem className="select-dropdown-MenuItems" value="January">January</MenuItem>
                                <MenuItem className="select-dropdown-MenuItems" value="February">February</MenuItem>
                                <MenuItem className="select-dropdown-MenuItems" value="March">March</MenuItem>
                                <MenuItem className="select-dropdown-MenuItems" value="April">April</MenuItem>
                                <MenuItem className="select-dropdown-MenuItems" value="May">May</MenuItem>
                                <MenuItem className="select-dropdown-MenuItems" value="June">June</MenuItem>
                                <MenuItem className="select-dropdown-MenuItems" value="July">July</MenuItem>
                                <MenuItem className="select-dropdown-MenuItems" value="August">August</MenuItem>
                                <MenuItem className="select-dropdown-MenuItems" value="September">September</MenuItem>
                                <MenuItem className="select-dropdown-MenuItems" value="October">October</MenuItem>
                                <MenuItem className="select-dropdown-MenuItems" value="Novemeber">Novemeber</MenuItem>
                                <MenuItem className="select-dropdown-MenuItems" value="December">December</MenuItem>
                            </Select>
                        </FormControl>
</Box>

What I tried wrapping in my FormControl tags:

<select
                        class={`${errorCondition === 'incompleteBirthday' || errorCondition === 'isWrongFormat' ? 'error-third-adjust-1' : "input-third-adjust-1"} ${isMonthSelected ? 'select-selected' : 'select-color'}`}
                        value={month}
                        onChange={handleSelectMonth}
                        onClick={handleMonthClick}
                        onBlur={handleMonthBlur}
                    >
                        <option value="" hidden>{month === '' ? monthPlaceholder : month}</option>
                        <option className="select-dropdown-options" value="January">January</option>
                        <option className="select-dropdown-options" value="February">February</option>
                        <option className="select-dropdown-options" value="March">March</option>
                        <option className="select-dropdown-options" value="April">April</option>
                        <option className="select-dropdown-options" value="May">May</option>
                        <option className="select-dropdown-options" value="June">June</option>
                        <option className="select-dropdown-options" value="July">July</option>
                        <option className="select-dropdown-options" value="August">August</option>
                        <option className="select-dropdown-options" value="September">September</option>
                        <option className="select-dropdown-options" value="October">October</option>
                        <option className="select-dropdown-options" value="Novemeber">Novemeber</option>
                        <option className="select-dropdown-options" value="December">December</option>
</select>

Would appreciate it greatly if anyone has a solution to this!

Create new document with base64 using office javascript API in office 365

Using this I am creating new document with base64String in word this is working in word desktop version but this is not working on Office 365.

async function CreateNewDoc(event) {
 try {
    await Word.run(async (context) => {
     // Use the Base64-encoded string representation of the selected .docx file.
     const externalDocument = base64;
             var externalDoc = context.application.createDocument(externalDocument);
    await context.sync();
    externalDoc.open();
    event.completed();
    await context.sync();
  });
} catch (error) {
  event.completed();
  console.error(error);
 }
}

error message on Office 365 The action isn't supported by Word in a browser its mean this functionality is not supported office 365 yet?

error message image

how to use JavaScript code in angular to create new folders?

I am trying to create new folders into my Angular project files (src/assets/images/NewFolder) based on the user input.

I have tried to add java script file in my assets folder

var fs = require('fs');
fs.mkdirSync('d:/stuff');`

and then added the reference in angular.json file:

"scripts": [
  "src/assets/test.js"
]`

Then I need to run this in my ts file but I don’t know how? I don’t have a function in the java script file above.

Getting API error on video upload and stream but locally its working fine

My code is hosted on cloud run service of GCP, here is the example snippet of the code:


    // Serve the video from Google Cloud Storage
    const bucket = storageClient.bucket(bucketName);
    const file = bucket.file(videoName);

    const videoSize = file.getMetadata().size;
    const range = req.headers.range;
    console.log(range, "Range ", videoSize, " videoSize");
    const CHUNK_SIZE =10 ** 6; // 1MB
    const start = Number(range?.replace(/D/g, '')) || 0;
    const end = Math.min(start + CHUNK_SIZE, videoSize - 1);
    const contentLength = end - start + 1;

    const headers = {
      'Content-Range': `bytes ${start}-${end}/${videoSize}`,
      'Accept-Ranges': 'bytes',
      'Content-Length': contentLength,
      'Content-Type': 'video/mp4',
    };

Please help, if any clue what i am missing.

The error i am getting 502, with response : upstream connect error or disconnect/reset before headers. reset reason: protocol error.

Keep in mind locally its working fine.

Magento 2 | Configurable Products: Change default value / title of (size) dropdown

Magento CE 2.4.6.
Configurable Products.

Option dropdowns of configurable products have the following default value:

Choose an Option…

I want to change this to the title of the attribute. I therefore copied the following template to my custom theme:

vendor/magento/module-configurable-product/view/frontend/templates/product/view/type/options.phtml

And did the following changes:

<option value=""><?= $block->escapeHtml(__('Choose an Option...')) ?></option>

To:

<option value=""><?= $block->escapeHtml($_attribute->getProductAttribute()->getStoreLabel()) ?></option>

This basically works. However, once the page has been loaded the default value is being updated / overwritten by some JS-File. I could not figure out which file is responsible for this. I was facing the same problem with dropdowns on BUNDLE pages and got help in this ticket:

Question 58558714

Do you have an idea which JS file is responsible for the overwrite?

Thank you!
Alex