Changing Values in a Form Causes Lag

I want to change the value of a from once a second, but when i use this code:

let btn = document.createElement("button");
function sleep (time) { // number of ms
  return new Promise((resolve) => setTimeout(resolve, time));
}
btn.innerHTML = "Save", btn.onclick = function() {
    var value = 0;
    while (true){
      sleep(1000).then(() => {if (value == 1){
        document.getElementById("input").setAttribute('value', '1');
        value += 1;
      } else if (value == 2){
        document.getElementById("input").setAttribute('value', '2');
        value += 1;
      } else if (value == 3){
        document.getElementById("input").setAttribute('value', '3');
        value += 1;
      } else if (value == 4){
        document.getElementById("input").setAttribute('value', '4');
        value += 1;
      } else if (value == 5){
        document.getElementById("input").setAttribute('value', '5');
        value += 1;
      } else if (value == 6){
        document.getElementById("input").setAttribute('value', '6');
        value += 1;
      } else if (value == 7){
        document.getElementById("input").setAttribute('value', '7');
        value += 1;
      } else if (value == 8){
        document.getElementById("input").setAttribute('value', '8');
        value += 1;
      } else if (value == 9){
        document.getElementById("input").setAttribute('value', '9');
        value += 1;
      } else if (value == 0){
        document.getElementById("input").setAttribute('value', '0');
        value = 0;
      }});
    }
}, document.body.appendChild(btn);

The tab completely locks up, and I am forced to reload it. I have also tried using document.getElementById("input").value = "value";, but that causes the same thing to happen. Does anyone know how to fix this (the form does not have a name)?

Vue 3: How to get boolean data from parent (using ) into child?

Firstly, I know this is probably a SUPER easy question, but I’ve been struggling for an hour and half and I’m kinda done with that. First vue project ever, so I’ve never had 2 components talk to each other, let alone when <script setup> is involved.

Any relevant docs that help me understand WHY this works this way would be wonderful. I want to learn how this works, but my google searching is getting me nowhere.

This app is simple, its just toggling light mode and dark mode on some cards. There’s more to it than what’s below, but I’ve stripped away the irrelevant (working) code for ease of reading.

My App.vue code:

<script setup>
import {ref, defineProps} from "vue";
import card from './components/card.vue'

const darkMode = ref(false);

const props = defineProps({
  darkMode: Boolean
})
</script>

<template>
// Bunch of stuff that is irrelevant to the scope of this problem, it works just fine. 
</template>

My card.vue code:

<script xmlns="http://www.w3.org/1999/html">
export default {
  data() {
    return {
      
    }
  },
}
</script>

<template>
  <h1 :class="{ 'text-white': darkMode }"> Content! </h1>
</template>

There’s more complexity to the project, but all I’m trying to do right now is get them to talk. I just want the class to be added based on whether darkMode is true or false in the parent.

If something seems out of place or random, it’s because i’ve spent an hour and half trying suggestions from docs and stackoverflow.

Any answers / explinations / docs / etc would be INCREDIBLE.

Thanks in advance!

How to position these divs on top of each other

I’m having so much trouble positioning three divs. I have 3 divs that only contain a background color and what i want to make is something similar to the google chrome logo.
here’s the code: https://codepen.io/xenia-radulovi/pen/bGLVgQm

<div class="container">
    <div class="bg-div red"></div>
    <div class="bg-div green"></div>
    <div class="bg-div yellow"></div>
</div>
.container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.red {
    position: absolute;
    left: 30%;
    width: 100%;
    height: 150vh;
    transform: rotate(58deg);
    background-color: #b71724;
    opacity: 1;
    transition: all 0.7s ease-in;
}
.green {
    position: absolute;
    right: 20%;
    width: 110%;
    height: 150vh;
    transform: rotate(-58deg);
    background-color: #2c4b2b;
    opacity: 1;
    transition: all 0.7s ease-in;
}
.yellow {
    position: absolute;
    top: 58%;
    width: 100%;
    height: 100vh;
    background-color: #d1aa3b;
    z-index: -1;
    opacity: 1;
    transition: all  0.7s ease-in;
}

This is just part of the code, there is more content that comes on top of all this, but this is basically the background for the page.

Right now, green is on top of red which is fine. But yellow is below both red and green and it should be on TOP of green and UNDER red div. Sort of like entangled divs.

Is there a way to put the yellow div on top of green and under red div to make it look more like google chrome logo.

Can I build a Chrome extension that updates an excel Office Online document

I am trying to figure out the best way to automate the gathering and exporting of information from a site I am visiting regularly to a excel sheet. I need to be able to both scrape information from the site as well as input some manually, which is why I thought a chrome extension would be a good idea.

I know that you cannot write to local files from a chrome extension, but I am trying to figure out if I can write to office online.

How to overcome API response limit

I have been tasked with extracting all product data from an imaginary eCommerce API with a fetch request and placing them into an array. The API has an unknown total count but will only return back 1000 products at a time. I need to somehow overcome this limit by utilizing minimum and maximum price in my request. I’m not really sure how to go about doing this. I’ve spent some time researching and trying a few things to no success. If someone could point me in the right direction, I would appreciate that. I code in javascript and have only been coding for a few months.

how to fix connect ENETUNREACH on npm on linux

i am not using a proxy im just a noob trying to learn how to develop with create-react-app locally on my machine(linux)

this is the output of tracepath registry.npmjs.org

 1?: [LOCALHOST]                        0.020ms pmtu 1500
 1:  2001:4451:664:1400:caf6:c8ff:fef2:bdcb                2.906ms !N
 1:  2001:4451:664:1400:caf6:c8ff:fef2:bdcb                0.995ms !N
     Resume: pmtu 1500

i think this proves im not using a proxy.

but i keep getting this error

npm ERR! code ENETUNREACH
npm ERR! syscall connect
npm ERR! errno ENETUNREACH

for anything npm. i dont know what to do.

i have tried..

  1. deleting the package.json in my home directory. deleting the
  2. package-lock.json in my home directory. deleting the .npm directory
    in my home direcory.
  3. clearing the cache with the npm config command
  4. setting https-proxy from the config to null setting proxy from the
  5. config to null setting the registry to https://registry.npmjs.org
  6. setting the registry to htpp://registry.npmjs.org uninstalled npm
  7. and dependencies then reinstalled unintsalled npm and dependencies
  8. then installed nvm and reinstalled node through that

npm install --verbose doesnt say any error messages

please somebody help me, i try just about anything shy of reinstalling my os.

Firebase / Firestore Add Document to Sub collection Version 9

Some reason, I just am not getting it.
I want to add a new document to a sub-collection. Here is my layout as follows:

Users----------- Collection
  UID----------- Document
    Categories-- Collection
      Category-- Document
      Category-- Document
           ...--

For the documents in the “Categories”, I want to add to Categories collection.
The Document is custom named.

I’ve tried the following:

    setDoc(doc(db, 'users', uid, 'categories', '[new Category Name Here]'), {
      name: 'Johnny Doey'
    })

This does not seem to work. The error I am receiving is ‘Undefined’.
I almost feel like there is something simple I am missing…. I’ve checked my auth rules. Everything checks out. Tried to test with hard strings in place of my variables, still no luck…

service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId}/{documents=**} {
  allow read, write: if request.auth != null && request.auth.uid == userId
}
}

}

Unless there is something going on with this.

Could someone please overlook this? Thanks!

How to get variable from JavaScript to PHP

i need to transfer a variable from js to a php page then insert it in the database

the Js code

    function tableText(tableCell) {
    var x =tableCell.innerHTML;
     console.log(x);
}

also tried the ajax

function tableText(tableCell) {
    var x =tableCell.innerHTML;
    console.log(x);
    $.ajax({  
    type: 'POST',
    url: 'try.php', 
    data: x ,
    complete: function(text){
         return text; }
 });
}

not sure if i got it right and i don’t know how to call it in the php page

so How to get variable from JavaScript to PHP ??

‘undefined’ when printing 2d array Javascript Chrome API

I get cookies using the chrome.cookies.getAll() function. I call that function twice and push both of the arrays(where the cookies are stored) into a new array called a[]. When I try to print a[] I get an array with two arrays inside of it (2d) and I can view them successfully.

I want to play around with those 2 arrays inside a[] to convert them to text and copy it to the clipboard. The problem is that I can’t access the elements inside a[], I keep getting undefined. How can I access the objects inside a[]?

background.js:

function getGoogleCookies()
{
    chrome.cookies.getAll({
        domain: "google.com", url: "https://google.com/"
    }, function (theCookies) {
        let cookies = theCookies
       // console.log(cookies) // <-- this works good
        a.push(cookies)
    });
}

function getGmailCookies()
{
    chrome.cookies.getAll({
        domain: "mail.google.com"
    }, function (theCookies) {
        let cookies = theCookies
        //console.log(cookies) <-- this works good
        a.push(cookies)
    });
}

let a = []

getGoogleCookies();
getGmailCookies();

console.log(a[0])
console.log(a) // <-- this works good

$scope variable getting updated before getting displayed from api requests

Please bear with me if the problem description below is not clear.

I have codes in 3 files design1Vo.htm, index.htm & api.php… From design1V0.htm function executeRequest is called on Initialization. Once called executeRequest function in index.htm calls another function getDataFmAPI which assigns value to the $scope.apiData variable based on the JSON array returned from api.php. $scope.apiData is used in design1V0.htm when looping. Issue is multiple api requests are being fired simultaneously. $scope.apiData gets updated before the data from the 1st api request is displayed on the screen.

Appreciate any insights that I can get to help resolve the issue.

design1V0.htm

    <dynamic ng-class="getProperties(object.id+barelement.id+containerelement.id+ddelement.id+ddcbelement.id+rowelement.id+rowcbelement.id+rowelement2.id,'linkedto','ng-class')" ng-if="object.type === 'dynamiccontentblock' || barelement.type === 'object' || containerelement.type === 'object' || ddelement.type === 'object' || ddcbelement.type === 'object' || rowelement.type === 'object' || rowcbelement.type === 'object' || rowelement2.type === 'object'" ng-init="executeRequest(getProperties(object.id+barelement.id+containerelement.id+ddelement.id+ddcbelement.id+rowelement.id+rowcbelement.id+rowelement2.id,'property','executeOnInit'));">
    <dynamicMainBlock ng-repeat="apiItem in apiData">        
        <dynamicContentBlock ng-repeat="dcbelement in elements | filter: {of: 'object'}: true | filter: {of_id: barelement.id}: true | orderBy:'loadpriority'" ng-include="dcbelement.path"></dynamicContentBlock>
    </dynamicMainBlock>
</dynamic>

index.htm

$scope.executeRequest = function(jsonString){ 
    jsonObject = JSON.parse(jsonString);         
    switch(jsonObject.functionToRun){
        case "toggleObject":{
            $scope.toggleObject(jsonObject.functionParameters.objID);
            break;
        }
            
        case "getDataFmAPI":{
            $scope.getDataFmAPI(jsonObject.functionParameters);
            break;
        }
    }
};
$scope.toggleObject = function(objID=''){
    if(objID != '')
        if(angular.element(document.querySelectorAll("."+objID+".w3-hide")).length > 0){            
            angular.element(document.querySelectorAll("."+objID+".w3-hide")).addClass("w3-show");
            angular.element(document.querySelectorAll("."+objID+".w3-hide")).removeClass("w3-hide");
        } else {
            angular.element(document.querySelectorAll("."+objID+".w3-show")).addClass("w3-hide");
            angular.element(document.querySelectorAll("."+objID+".w3-show")).removeClass("w3-show");
        };
};    
$scope.getDataFmAPI = function(jsonObject){
    var httpString = '';
    httpString += $scope.wslink+"content/plugins/api.php?";
    httpString += (jsonObject.table != undefined)?'table='+jsonObject.table:'';
    httpString += (jsonObject.where != undefined)?'&where='+jsonObject.where:'';
    httpString += (jsonObject.primary != undefined)?'&primary='+jsonObject.primary:'';
    httpString += (jsonObject.orderby != undefined)?'&orderby='+jsonObject.orderby:'';
    httpString += (jsonObject.fetch != undefined)?'&fetch='+jsonObject.fetch:'';
    httpString += (jsonObject.user != undefined)?'&user='+jsonObject.user:'';
    httpString += (jsonObject.key != undefined)?'&key='+jsonObject.key:'';        
        
    $http.get(httpString).then(function(response){            
        $scope.apiData = response.data;
        console.log(response.data);
    });
};

api.php

$queryRecords = $DBObj->fetchAllRecordsArray();
                                    if(!empty($queryRecords)){
                                        echo json_encode($queryRecords,JSON_NUMERIC_CHECK);
                                        exit;
                                    }

How to aggregate two arrays?

Imagine I have the amount of fruit pieces as described in the array.

[["apple",2],["banana",2],["apple",1],["kiwi",2],["banana",2],["mango",1]]

As you can see I have 3 apples only now that is noted in two separate arrays. And I don’t want that, because I want the words to occur only 1 time and the numbers to add up so I get this result.

[["apple",3],["banana",4],["kiwi",2],["mango",1]]

Problema con la función focus en angular

I hope you can help me, I just started as a programmer and I have a newbie problem,
I have two inputs, I want to write a series of numbers in my first input (DO) and then automatically pass to the second input (communal code).

Inputs

I understand that it is done with focus but I can’t get good results.
I look forward to your responses, thank you.

Can I map two columns in a one-to-many relationship in Prisma?

I’m trying to create a prisma schema, where I have an Order model, and a Client model. I would like to have a one-to-many relation between clients and orders.

I have it working with this Order model:

clientId     Client            @relation(fields: [clientId], references: [id])
clientId     Int

But wanted to also include the client name. Something like this doesn’t work:

client       Client            @relation(fields: [clientName, clientId], references: [name, id])
clientName   String
clientId     Int

This gives me the error

Error validating: The argument `references` must refer to a unique criteria in the related model `Client`. But it is referencing the following fields that are not a unique criteria: name, id

Is this something that is possible within the Prisma schema? I can do it with my controller in NestJS, but ideally I would want to be done in the Prisma layer.

Create a react state that changes with time

I am creating a game with react and i want to add a chronometre feature to track time but i tried to use settimeout and it failed bcs every render the settimeout recall and i tried setinterval but failed also can anyone suggest me a way to to this the game is a tenzies game

Bing Image Search using JavaScript for multiple image searches

I desperately need assistance.
I have an app with a list of named items, Url place holder and an action button that when clicked, it should use the named list to perform a Bing image search and pull each image Url and save it into my app’s Url place holder. Here is my code below. What am I missing here?
And what if I want to fetch more than one image?
Kindly assist.

var imageToSearchQlikSenseVariable = 'vSelection';

var bingImageApiBaseUrl = "https://bing-image-search1.p.rapidapi.com/images/search?q=";
var bingImageApiHost = "bing-image-search1.p.rapidapi.com";

var bingImageApiKey = "r5graregerq5geragae5geg5ergeg5"; //Fake key
var bingImageApiAdditionalParams = "&count=1&safeSearch=Strict";
var data = null;
var xmlHttpRequest;

function getCurrentQlikSenseApp(){
  var appId = qlik.currApp().id;
  return qlik.openApp(appId);
}

async function getImageToSearchString() {
  var app = getCurrentQlikSenseApp();
  var image;
  await app.variable.getContent(imageToSearchQlikSenseVariable, function(reply){
      image = reply.qContent.qString;
  });
  return image;
}

function initiateXmlHttpRequest(){
  xmlHttpRequest = new XMLHttpRequest();
  xmlHttpRequest.withCredentials = true;
}


function setImageUrlQlikSenseVariableWhenXmlHttpRequestIsDone(){
  var app = getCurrentQlikSenseApp();
  xmlHttpRequest.addEventListener("readystatechange", function () {
        if (this.readyState === this.DONE) {
            const responseJson = JSON.parse(this.responseText);
            const imageUrl = responseJson.value[0].contentUrl;
            app.variable.setStringValue('vImageUrl', imageUrl);
        }
    });
}

function getEncodedUri(imageToSearch) {
  var uriToGet = bingImageApiBaseUrl + imageToSearch + bingImageApiAdditionalParams;
  return encodeURI(uriToGet);
}

function addHeaderToRequest(){
  xmlHttpRequest.setRequestHeader("x-rapidapi-host", bingImageApiHost);
  xmlHttpRequest.setRequestHeader("x-rapidapi-key", bingImageApiKey);
}


async function execute(){
    var imageToSearch = await getImageToSearchString();
    initiateXmlHttpRequest();
    setImageUrlQlikSenseVariableWhenXmlHttpRequestIsDone();
    xmlHttpRequest.open("GET", getEncodedUri(imageToSearch));
    addHeaderToRequest();
    xmlHttpRequest.send(data);
  }

  execute();