Skip to main content

Posts

Showing posts with the label Active questions tagged javascript - Stack Overflow

My reset button not resetting the game mode in Tic Tac Toe (Noughts and Crosses)

I have created a Tic Tac Toe game (Noughts and Crosses in the UK!) and have finished almost everything except perhaps improving the computer AI (its just random at the moment). However, there is one bug that I can't seem to fix. When you first play the game you get the choice of playing against another human (player 2) or computer. Once this "human" or "computer" button is pressed it will save the information in a variable "let choiceComp" as either "human" or "comp". This will then call their respective functions, computerGame() or humanGame(), once the player enters their details and the subsequent start button is pressed. This works fine the first time around but when the reset button is pressed and the alternative game mode is selected (e.g. human first, then computer second - or vice versa), the same game mode will continue as the first time. I've reset the choiceComp variable as an empty string, along with everything els

Will window.close work only work if the window shares a domain with the window trying to close it?

I'm trying to understand when window.close() will / won't work. I know there are some requirements around the window being script closeable etc., but it seems like there are some additional requirements that I can't find formally laid out (at least, not laid out in terms I can't understand with my current javascript knowledge.) At a high level, my use case is as follows: a user clicks a button I do some stuff and then do something like windowRef = window.open("http://example.com/somedocument.pdf","popup") . Once the user takes clicks a different button, I want to be able to call windowRef.close() and have it close the pdf I opened in a popup. My current implementation works as long as the url I'm opening shares a domain with the window that's trying to close it, and not otherwise. That's fine (I can guarantee the PDF will come from the same domain as the window trying to close it) but I'd like to understand why this doesn'

Buttons of Edit and Delete in DataTables Vue 3

I'm trying to include Edit and Delete buttons in the actions column in DataTables, the buttons are rendered on the screen, but the @click event doesn't work, and doesn't return an error message, can you check where I'm going wrong? Thank you all. The MontaTable component was created in another file. <template> <div id="divClientes"> <div style="padding-bottom: 20px; color: navy; font-weight: bold;"> <h3>Clientes cadastrados</h3> <button type="button" @click="novoCliente" class="btn btn-secondary">Novo Cliente</button> </div> <MontaTabela :rows="rows" :columns="columns" /> </div> </template> <script> /* eslint-disable */ import MontaTabela from '@/components/MontaTabela/MontaTabela.vue'; import http from '@/services/http.js'; import { FuncoesAuxiliares } from '@/helpers/FuncoesAuxiliares.vue'

How to redirect to index.php after checking the email if already exist in database?

Im trying to use Google OAuth 2.0 using the GSI library. Im using localhost to try to log in (authenticate) using google account. So I need to get the email address to check if already exist in the database. If yes, proceed to assigning the email address to session and redirect to index.php. If not, user will redirect to a form to complete the sign-up process. The problem is, after I select Google account, it redirects to login.php. I tried to surf for answers but it's no use as the tutorials are using (gapi) oauth 2.0 The files are: login.php google_signin.php (where the checking of email takes place) Here is the code for reference. Suggestions are highly appreciated <script> function onSignIn(response) { const { id_token, access_token } = response.credential; fetch('google_signin.php', { method: 'POST', headers: { 'Content-Type': 'application/j

Cannot access member arrays in Prisma model with a relational table. Using next.js, prisma, typescript

I have two tables defined with a relationship. Categories and Articles. Prisma build the relationship and all that looks good. Here is the definition of the Category table. model Category { id Int @id @default(autoincrement()) parentId Int? name String @unique articles Article[] } model Article { id Int @id @default(autoincrement()) date DateTime @default(now()) title String @unique summary String @db.Text text String @db.MediumText userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) categoryId Int category Category @relation(fields: [categoryId], references: [id]) image String? tags String? commentsEnabled Boolean @default(true) comments Comment[] likes Like[] } When I query the categories from Prisma, I do it like this: const categories = await

How to implement this using html and csss

I want to implement this, but can't find a way: I tried CSS grid but it wasn't working out, tried to think of how i would do it in flex box but still couldn't figure it out, so anyone who has done it before it would be helpful with code Via Active questions tagged javascript - Stack Overflow https://ift.tt/DA1eBNM

SvelteKit form checkboxes not accurately displaying checked state after form submission

I have a SvelteKit route with a +page.server.ts file which has a load function that retrieves a user record from a database. The user has a string property containing a comma delimited list of "collection" ids that user has access to. In the +page.svelte page, I display a form with checkboxes for each collection to allow an admin user to grant or revoke permissions to collections. Here is my code for displaying the checkboxes <form method="post" action="?/setCollections" use:enhance> <input type="hidden" name="email" value={data.user.email} /> <fieldset style:padding-left="1rem"> {#each data.collections as collection (collection.id)} <div style:margin-bottom=".5rem"> <input id={collection.name} name={collection.name} type=&q

Mysql2 error in NextJS13, cant find module Net

I'm trying to acquire information from a mysql database in nextjs13 using the mysql2 dependency, like this: import mysql from 'mysql2/promise' export const getData = async(req, res) => { const dbconnection = await mysql.createConnection({ host: "hostname", database: "databasename", user: "username", password: "password", }); try { const query = "SELECT productid, productname, productimage FROM products"; const values = []; const [data] = await dbconnection.execute(query, values); dbconnection.end(); res.status(200).json({ products: data }); } catch (error) { // unhide to check error // res.status(500).json({ error: error.message }); } return dbconnection } At first the error was that the net module was missing, which is called when mysql.createConnection is used. Then when I added the module, i

Vue ref change does not apply changes to the component after update

I have a form implemented with vue3. The form consists of three text inputs and a checkbox group. I am using bootstrap-vue form and it's checkbox-group for this. I call an api to set default values on the form, after the api responds I update the ref like the code below and all three text inputs get updated just fine . The problem is with the checkbox group component. The checked items won't get checked although they are inside of the tagList ref. // I set the formValues ref and api call to get default values in this composable. // taglist will be a list of strings: tagList = ['example'] const formValues = ref<IArticleFormValues>({ title: '', body: '', description: '', tagList: [], }); const { data, isFetching } = useQuery({ queryKey: ['fetchArticleBySlug', slug], queryFn: () => fetchSingleArticleService(slug) }); watch(data, () => { if (data.value?.article) { formValues.value

display a component by exporting in react

I am trying to lean react by solving a problem in react. Providing the react code challenge below. I am seeing the below error in browser. I googled but still no luck, not sure how to solve it. Providing my code below and stackblitz. Can you guys help me. Property 'stateDropdown' does not exist on type 'JSX.IntrinsicElements'.(2339) https://stackblitz.com/edit/stackblitz-starters-ngl4yu?description=React%20%20%20TypeScript%20starter%20project&file=src%2Fcomponents%2FstateDropdown.tsx,src%2Fcomponents%2FstateDropdown.css,src%2FApp.tsx&title=React%20Starter import { FC } from 'react'; import './style.css'; import { stateDropdown } from './components/stateDropdown'; export const App: FC<{ name: string }> = ({ name }) => { return ( <div> <stateDropdown /> <h1>Hello {name}!</h1> <p>Start editing to see some magic happen :)</p> </div> ); }; coding challenge h

Unable to load image from url fetched from sqlite database

I have a Web app(Electron.Js) using HTML,CSS & Javascript, where in I am saving an image url and background color as chosen by user to Sqlite database using : const reader = new FileReader(); reader.onload = function () { const imageUrl = reader.result; query = "INSERT INTO QuizWindow VALUES('" + imageUrl + "','" + selectedColor + "');"; db.queryStatement(query, (err, rows) => { if (err) { console.error(err.message); } else { rows.forEach((row) => { console.log(row); }); } }); }; reader.readAsDataURL(imageInput.files[0]); which works fine. But when I fetch the same data from Sqlite using: function LoadBackground() { var query = "SELECT * FROM QuizWindow ;"; db.queryStatement(query, (err, rows) => { if (err) { console.erro

RRweb is duplicating objects inside the replay

Im trying out rrweb & rrweb-replayer for its recording and replaying abilities, im having trouble recording properly and replaying. some of the issues im having: 1.[replayer] Node with id 'XYZ' not found. 2. Source map error: Error: request failed with status 404 Resource URL: null (Unsure if relevent) 3. the replay is not the same as the final HTML render- there are duplciate objects in the replay the recording and replaying are happening in this app.jsx in my react project: A visual compression: What the rrweb replayer records: my example project can be found in this link: use the package.json to install everything you need - the project uses vite,zustand and react Via Active questions tagged javascript - Stack Overflow https://ift.tt/7uKQ1jw

Simplybook book(). Instance not defined error

I'm relatively new to programming and I have to create a booking system for the company I work at using Simplybook.me This is the code I've tried jQuery(document).ready(function() { var loginClient = new JSONRpcClient({ 'url': 'https://user-api.simplybook.me' + '/login', //Connects to the API 'onerror': function(error) { instance.error(error); } }); client = null, $company = "COMPANY"; $user = "USER"; //Fill in this data. Name of the account: email $pass = "PASS"; //Fill in this data. Password var token = loginClient.getUserToken($company, $user, $pass); this.client = new JSONRpcClient({ 'url': 'https://user-api.simplybook.me' + '/admin/', 'headers': { 'X-Company-Login': $company, 'X-User-Token': token }, 'onerror': function(error) { instance.error(error); } }); // Booking trial (

RangeError [BitFieldInvalid]: Invalid bitfield flag or number: Messages

I can’t figure how to solve this error, can someone help me in detail since I’m trying to make a bot? I’m sorry if I’m dumb.. Here is the message: ⠀ ⠀ ⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀ ⠀⠀⠀ ⠀⠀⠀ ⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀ Via Active questions tagged javascript - Stack Overflow https://ift.tt/dOrgZMn

Will change of constructor's prototype influence the instantiated object?

If I have a function (constructor) with a defined prototype, let's say: function Student(name) { this.name = name; } Student.prototype.sayHello = function() { console.log(`Hello, my name is ${this.name}`); } And I instantiate and object using that function (from what I know it should set newly created object's property _prototype to the above prototype object in the moment of creation and set constructor property to Student function). const s1 = new Student('John'); s1.sayHello(); I am sure calling sayHello() would work, however, what if I change the Student 's prototype like this? Student.prototype.sayGoodbye = function() { console.log(`Goodbye, my name is ${this.name}`); } Should s1 be able to call sayGoodbye ? I've read that the _prototype should't change, so in that logic it should throw an error, however, trying it in Chrome's console panel and node.js project it worked and s1 could invoke sayGoodbye . Can someone help me underst

What is the proper way to link a section on a page using locomotive scroll? [closed]

I have two section links on my page: home and about. Both of them do not work when you are below the respective sections. When the about link is clicked from the home section, it does scroll properly, but all of the content above is removed, other sections load in late and there is extra space at the bottom. This only goes back to normal when the home link is clicked. Actually, that is the only instance where the home link works. What am i doing wrong ? I will provide code to reproduce it if needed. Via Active questions tagged javascript - Stack Overflow https://ift.tt/HvpqlRn

Creating a Button with JavaScript

I'm currently learning JavaScript. I've been attempting to create a navbar button that opens the menu when clicked. After multiple attempts and changes to the code, I didn't solve the problem. HTML <nav class="nav"> <div class="logo">AdoptaPet</div> <button id="navBtn"><i class="bi bi-list abrirNav"></i></button> <ul id="abrirMenu" class="nav-links"> <i class="bi bi-x fecharNav"></i> <li><a href="">Home</a></li> <li><a href="">Sobre Nós</a></li> <li><a href="">Loja</a></li> <li><a href="">Cães para Adoção</a></li> <li><a href="">Detalhes do Cão</a&g

Create a regular expression to match big numbers

I get a response from the backend as text in which I have to find a match for numbers which is minimum 16 digits in length. Let's say I have data something like this: {"BIG_INT": 123456789012345675,"BIG_INT_ARRAY_SINGLE": [123456789012345676],"BIG_INT_ARRAY_MULTIPLE": [123456789012345661,12345678901234562,12345678901234563,12345678901234564],"STRING_BIG_INT_ARRAY": "[12345678901234567,12345678901234567, 12345678901234567,12345678901234567]","STRING_BIG_INT":"12345678901234567","BIG_INT_FLOATING_DECIMAL": 12345678901234567.76543210987654321} There are certain conditions where it should not match a number: If the number is enclosed within double quotes: ("STRING_BIG_INT":"12345678901234567" )` If the numbers are within string enclosed array: "STRING_BIG_INT_ARRAY":"[12345678901234567,12345678901234567]" If the number is fractional: "BIG_INT_FLOATING_D

js and css are not applied to html as static files of nestjs backend solution on nginx server (localhost works correctly)

Hello dear dev community. i would appraciate your help with complex issue related to static content (html, css, js) and nginx configuration. I have backend solution with nestjs framework that returns to frontend some static content (html, css, js). When I launch it locally localhost works correctly. But after deploy to server with nginx configuration I faced with issue: css styles and js scripts are not applied to html. Could you please advise what would be the possible fixes of this issue. Via Active questions tagged javascript - Stack Overflow https://ift.tt/wQKps2r

Content Overflows Other Sections

I'm a beginner to all of this coding and simply trying to build my store's website from scratch. I've learned a lot in HTML codes so far, and have come across this tab content style that would benefit many of our pages. Unfortunately, I can't seem to find a way to get around the fact that the code doesn't build a frame around the entire content style that is submitted, so when I submit this code to the site and attempt to add a new section, the tab code overlaps the new section. It looks like the frame only goes around the text content, and stops when the <div class="tab"> starts. For reference: see the image attached of the code submitted to the webpage with the content overlapping on the new "TESTTEST1212" text section. Code Submitted with overlapping "test" section See HTML Tab Content Section Code Below: <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, ini