I often see on sites that if you delete or change some values from localStorage, they are restored to their original state after the site is reloaded. How is this done?
I tried to look for a solution on the Internet, but I couldn’t find anything.
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
I often see on sites that if you delete or change some values from localStorage, they are restored to their original state after the site is reloaded. How is this done?
I tried to look for a solution on the Internet, but I couldn’t find anything.
I’m working on the backend settings of a WordPress plugin and thought I’d build a simple table enable editing of the data in the Custom Options menu of the plugin.
In case you are looking at the screenshot and wondering, it is a data on the anniversaries of loved ones who have passed away in previous years, known in Church as “the Year’s Mind”. Nothing sinister, I assure you!
The PHP is
$html .= "<form name='updateRow_". $post->ID ." method='post' action='includes/yearsmind-update.php'>";
$html .= "<input type='hidden' name='ID' value='" . $post->ID . "'>";
$html .= "<input type='hidden' name='firstName' value='" . $post->firstName . "'>";
$html .= "<input type='hidden' name='middleName' value='" . $post->middleName . "'>";
$html .= "<input type='hidden' name='lastName' value='" . $post->lastName . "'>";
$html .= "<input type='hidden' name='fullDate' value='" . $post->fullDate . "'></form>";
The button is:
<button type='button' onclick='document.updateRow_".$post->ID.".submit()')>Update</button>
The $html string is written out nicely to the backend, and when I click on the update button, I can pick up the javascript function and display the passed $post->ID
However, I cannot seem to programmatically submit the specified form. The submit method throws an error:
Uncaught TypeError: Cannot read properties of undefined (reading 'submit')
I have tried just passing a reference to the form via Form ID which gets through to a JavaScript function and displays passed reference, fine, but as the button can only be clicked after the form has fully loaded, it seems that none of the document.addEventListener('DOMContentLoaded', () => {
events make any difference.
I have tried to simplify it by programming in the submit code into the form, and still it is throwing up an error!
Once the form is submitted to a PHP file, I plan to construct the UPDATE sql and execute it, but I’d just like to get the data POSTed first!
I bet the solution is obvious, but I can’t work out the solution without your generous help… Thank you.
I have deployed the contract made using solidity locally using hardhat. When I get the contract and make a call to a view function using the contract in React website I get a CALL_EXCEPTION error in the console and also get a error in hardhat node console saying “Warning: Calling an account which is not a contract”.
This is the function I use in React
const GetMessage = async () => {
try {
const {ethereum} = window;
if (ethereum) {
const provider = new ethers.providers.Web3Provider(ethereum);
const signer = provider.getSigner();
const supplyChainContract = new ethers.Contract(
contractAddress,
contractABI,
signer
);
let count = await supplyChainContract.GetCount();
console.log(count.toNumber());
}
else
setMessage("Ethereum Not Found");
} catch (error) {
console.log(error);
return null;
}
};
This is the contract
pragma solidity ^0.8.17;
import "../node_modules/hardhat/console.sol";
contract SupplyChain {
uint256 public count;
function GetCount() public view returns (uint256){
return count + 1;
}
}
I am finishing my first project, blackjack game, and I need to convert window and document objects to corresponding jQuery. I’ve figured out most of them with an exception of document.createElement(“img”).
The code in question is as follows:
let cardImg = document.createElement("img");
let card = deck.pop();
cardImg.src = "./cards/" + card + ".png";
yourSum += getValue(card);
yourAces += ValueOfAce(card);
$("#PLAYERcards").append(cardImg)
In this code the new card is added, after which the values are computed.
What I’ve tried is:
let card = deck.pop();
let cardImg = $(".img").attr("src", "./cards/" + card + ".png");
yourSum += getValue(card);
yourAces += ValueOfAce(card);
$("#PLAYERcards").append(cardImg);
The code does add a new card value to the player’s total, and the messages come up when the player has exceeded the total of 21 but the new card image doesn’t show. Visually, it looks like player has only 2 cards!!
I’m sure that’s something very simple but I’m awfully new to jQuery and would appreciate any suggestion.
Trying to handle the popup window closing up. But I’m having an error. Is the issue reffered to the rhis keyword ?
https://codesandbox.io/s/tours-test-slick-v1uw96?file=/index.js:626-1309
// Get the modal
const modal = document.getElementById("myModal");
// Get the button that opens the modal
const btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
const close = document.getElementsByClassName("closeBtn");
// When the user clicks the button, open the modal
btn.onclick = function () {
modal.style.display = "block";
};
// When the user clicks on <span> (x), close the modal
close.onclick = function () {
modal.style.display = "none";
};
// When the user clicks anywhere outside of the modal, close it
window.onclick = function (event) {
if (event.target == this.modal) {
modal.style.display = "none";
}
};
I’m working on a real life project and decided to test the new App directory that comes with the Next js 13 version, I noticed some glitches like my images and fonts not loading properly, etc. I would like to stop using the experimental app Dir.
Is there a way to opt out of the experimental app directory locally without having to reinstall next-app?, please I’m new to Next js.
Here is my next.config.js
/** @type {import('next').NextConfig} */
const path = require("path");
const nextConfig = {
experimental: {
appDir: true,
},
sassOptions: {
includePaths: [path.join(__dirname, "styles")],
},
reactStrictMode: true,
images: {
loader: "akamai",
path: "/",
},
};
module.exports = nextConfig;
Whenever I put the appDir as false, I get the following error
Error: > The `app` directory is experimental. To enable, add `appDir: true` to your `next.config.js` configuration under `experimental`. See https://nextjs.org/docs/messages/experimental-app-dir-config
at Object.findPagesDir (C:UsersFavourOneDriveDocumentsCode SchoolWebDevelopmentProjectsecommercefrontendnode_modulesnextdistlibfind-pages-dir.js:80:19)
at DevServer.getRoutes (C:UsersFavourOneDriveDocumentsCode SchoolWebDevelopmentProjectsecommercefrontendnode_modulesnextdistserverdevnext-dev-server.js:141:59)
at new Server (C:UsersFavourOneDriveDocumentsCode SchoolWebDevelopmentProjectsecommercefrontendnode_modulesnextdistserverbase-server.js:115:47)
at new NextNodeServer (C:UsersFavourOneDriveDocumentsCode SchoolWebDevelopmentProjectsecommercefrontendnode_modulesnextdistservernext-server.js:73:9)
at new DevServer (C:UsersFavourOneDriveDocumentsCode SchoolWebDevelopmentProjectsecommercefrontendnode_modulesnextdistserverdevnext-dev-server.js:100:9)
at NextServer.createServer (C:UsersFavourOneDriveDocumentsCode SchoolWebDevelopmentProjectsecommercefrontendnode_modulesnextdistservernext.js:152:24)
at C:UsersFavourOneDriveDocumentsCode SchoolWebDevelopmentProjectsecommercefrontendnode_modulesnextdistservernext.js:165:42
at async NextServer.prepare (C:UsersFavourOneDriveDocumentsCode SchoolWebDevelopmentProjectsecommercefrontendnode_modulesnextdistservernext.js:134:24)
at async Server.<anonymous> (C:UsersFavourOneDriveDocumentsCode SchoolWebDevelopmentProjectsecommercefrontendnode_modulesnextdistserverlibrender-server.js:92:17) {
type: 'Error'
}
I have a completed transaction and I have its transaction ID. I am trying to query that transaction using the following code:
const transactionQueryExecuteTx = await new TransactionReceiptQuery()
.setTransactionId(transactionId)
.setMaxAttempts(maxAttempts)
.setGrpcDeadline(grpcDeadline)
.execute(this.client);
However, I am getting an error saying that the transaction receipt was not found, even though I can see the transaction on the Hedera network. Can anyone help me troubleshoot this issue?
currently making an e-commerce application and trying to make the checkout api that will credit multiple stores with their respective amounts due. I’m sure the logic works because the history can be created properly but it appears the problem with the update part of the api is, it doesn’t save and return the update value before running the loop again here’s the source code. the issue is at the add to seller function
export default async function PayNow(req, res) {
if (req.method === "POST") {
console.log('CONNECTING TO MONGO');
await connectMongo();
console.log('CONNECTED TO MONGO');
const { _id } = JSON.parse(req.body)
const sender = await Student.findById(_id)
const orders = await CheckOutItem.find({ user: _id })
let store = []
for (let i = 0; i < orders.length; i++) {
store.push(orders[i].storename)
}
const n_store = [... new Set(store)]
let fee = 0
// collect delivery fee
for (let i = 0; i < n_store.length; i++) {
if (orders[i].mod === "PickUp") {
fee = 0
} else {
fee = fee + 100
}
}
const o_fee = fee / n_store.length
//collect total
let sum = 0
for (let i = 0; i < orders.length; i++) {
sum += orders[i].amount
}
let total = sum + fee
//pay for all items
for (let i = 0; i < orders.length; i++) {
if (orders[i].p_status === "Pay on Delivery") {
if (sender.account_bal < total) {
return res.status(256).json({
message: "insufficient funds",
});
} else {
//subtract from student
const new_sender_bal1 = sender.account_bal - sum
const sender_bal = await Student.findById(_id).updateOne({ account_bal: new_sender_bal1 })
const l_store = await Promise.all(store.map(async (name) => {
const o_store = Seller.findOne({ storename: name })
return (o_store)
}))
//add to sller
for (let i = 0; i < l_store.length; i++) {
await Seller.findByIdAndUpdate(l_store[i]._id, { account_bal: l_store[i].account_bal + orders[i].amount }, { new: true })
}
return res.status(200).json(orders[0].amount)
}
} else {
return res.status(259).json({
message: "Already paid",
});
}
}
//pay deliveriy fee
if (fee > 0) {
const new_sender_bal = sender.account_bal - fee
const new_user_bal = await Student.findById(_id).updateOne({ account_bal: new_sender_bal })
// console.log(new_sender_bal)
const l_store = await Promise.all(n_store.map(async (name) => {
const o_store = Seller.findOne({ storename: name })
return (o_store)
}))
for (let i = 0; i < l_store.length; i++) {
const main_sell_bal = l_store[i].account_bal + o_fee
const new_main_sell_bal = await Seller.findById(l_store[i]._id).updateOne({ account_bal: main_sell_bal })
const dev_history = await TransferHistory.create({
sender: sender.firstname + sender.lastname,
reciever: l_store[i].storename,
amount: o_fee,
trans_type: "DEBIT",
send_id: _id,
rec_id: l_store[i]._id
})
const dev_history2 = await TransferHistory.create({
sender: sender.firstname + sender.lastname,
reciever: l_store[i].storename,
amount: o_fee,
trans_type: "CREDIT",
send_id: _id,
rec_id: l_store[i]._id
})
}
return res.status(200)
} else {
return res.status(200).json({
message: "no delivery fee but successful"
})
}
} else {
return res.status(400).json({
message: "wrong request",
});
}
}
How to write a regex to filter all the string with relative path format i.e.starts with ser_ver/ and ends with .dat and inbetween may have _,-,/ like following,
file1 ser_versha-resubfolder_1.dat
file2 ser_versha-refolder1subfolder_1subfolder_2.dat
file3 serversha-recomplexsubfolder_1.dat
file4 serversha-re5555AB12subfolder_1subfolder_2subfolder_3.dat
expected:
ser_versha-resubfolder_1.dat
ser_versha-refolder1subfolder_1subfolder_2.dat
I need to link when i click “Submit” button to open another html page and to change text on it.
my html code
<div class="welcome">
<h2 id="welcomeHeader">Welcome to Quiz</h2>
<h3 id="nameHeader">Write Your Name</h3>
<input id="userName">
<button type="submit" onclick="start()">Let's Go!</button>
</div>
my quiz code
<div>
<h2 id="welcomeText">Hello</h2>
</div>
my JS code
let userName = document.getElementById('userName');
let nameHeader = document.getElementById('nameHeader');
let welcomeText = document.getElementById('welcomeText');
function start() {
window.location.href='quiz.html';
welcomeText.innerHTML = 'Hello ' + userName.value; + ', welcome to Quiz';
}
Code opening quiz.html page but it doesn’t rewrite text in #welcomeText?
Any help?
I tried different solutions but nothing works. I need all kind of help.
So i am trying to learn Quasar and Vue by building a Twitter clone from a freecodecamp tutorial and all was well until i tried to convert a unix timestamp with date-fns into a relative time like e.g. “5 Minutes ago” to display the time passed since a tweet was posted. The exact code looks like this:
This is the Object i want to display in the upper right corner to indicate the time
<q-item-section side top>
{{ tweet.date | relativeDate }}
</q-item-section>
further down i implemented the function to filter the dates into the expected format inside the export default function
filters: {
relativeDate(value) {
return formatDistance(value, new Date())
}
}
There is legit nothing else happening here and i don´t get the promised String from date-fns function but a difference of the unix times, which i can calculate without date-fns for myself anyway ^^´.
I don´t get any errors only the wrong value. If you need any other infos please let me know and thanks in advance for any help.
I tried other functions like formatDistanceToNow() from date-fns but still got no correct value. Also i am building in quasar vue using typescript but turned the lang setting for this script section off because typescript didn´t accept the properties of the changed value when i piped the function into the object parenthesis. I don´t get any errors when i use js instead of ts and everything else still works.
I am new to javascript and I can’t find any good tutorials so if anyone can help
…………………….
I’m working on a form validation with the jQuery validation plug-in and it’s not working properly.
I tried everything but can’t find where I’m doing wrong
Also I have two forms, but I’m showing only the first form’s code because they are pretty much the same
I already checked my link tags, but they don’t seems to be wrong at all
$().ready(function() {
$("#formFisica").validate({
onkeyup: false,
onfocusout: false,
rules: {
nomeFisica: {
required: true,
},
cpfFisica: {
required: true,
number: true,
maxlength: 11
},
dddFisica: {
required: true,
number: true,
maxlength: 2
},
telFisica: {
required: true,
number: true,
maxlength: 9
},
emailFisica: {
required: true,
email: true
},
confEmailFisica: {
required: true,
equalTo: "#emailFisica"
},
senhaFisica: {
required: true,
minlength: 6,
maxlength: 15
},
confSenhaFisica: {
required: true,
equalTo: "#senhaFisica"
},
},
messages: {
nomeFisica: {
required: "Esse campo não pode ser vazio"
},
cpfFisica: {
required: "Esse campo não pode ser vazio",
number: "Esse campo só aceita números",
},
dddFisica: {
required: "Esse campo não pode ser vazio",
number: "Esse campo só aceita números",
},
telFisica: {
required: "Esse campo não pode ser vazio",
number: "Esse campo só aceita números",
},
emailFisica: {
required: "Esse campo não pode ser vazio",
email: "Digite um endereço de e-mail valido"
},
confEmailFisica: {
required: "Esse campo não pode ser vazio",
equalTo: "Os e-mails não correspondem"
},
senhaFisica: {
required: "Esse campo não pode ser vazio"
},
confSenhaFisica: {
required: "Esse campo não pode ser vazio",
equalTo: "As senhas não correspondem"
},
}
});
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container text-center">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" value="" id="flexCheckDefaultFisica">
<label for="flexCheckDefaultFisica" class="form-check-label">Pessoa Física</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" value="" id="flexCheckDefaultJuridica">
<label for="flexCheckDefaultJuridica" class="form-check-label">Pessoa Jurídica</label>
</div>
</div>
</div>
<div class="container pt-2" id="containerFisica">
<form id="formFisica">
<div class="form-group pt-2 pb-2">
<label for="exampleInputEmail1">Nome completo</label>
<input type="text" class="form-control" id="nomeFisica" aria-describedby="emailHelp" placeholder="Insira seu nome" required/>
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputPassword1">CPF</label>
<input type="number" class="form-control" id="cpf" placeholder="Insira seu CPF" />
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputPassword1">DDD</label>
<input type="number" class="form-control" id="dddFisica" placeholder="DDD" />
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputPassword1">Telefone</label>
<input type="number" class="form-control" id="telFisica" placeholder="Número de telefone" />
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputEmail1">E-mail</label>
<input type="email" class="form-control" id="emailFisica" aria-describedby="emailHelp" placeholder="Insira seu e-mail" />
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputEmail1">Confirmar E-mail</label>
<input type="email" class="form-control" id="confEmailFisica" aria-describedby="emailHelp" placeholder="Confirme seu e-mail" />
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputPassword1">Senha</label>
<input type="password" class="form-control" id="senhaFisica" placeholder="Insira sua senha" />
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputPassword1">Confirmar Senha</label>
<input type="password" class="form-control" id="confSenhaFisica" placeholder="Confirme sua senha" />
</div>
<div class="form-check pt-2">
<input type="radio" class="form-check-input" id="aceitoEmailFisica" />
<label class="form-check-label" for="aceitoEmailFisica">Aceito receber e-mails</label>
</div>
<div class="form-check pt-2">
<input type="radio" class="form-check-input" value="" id="flexCheckChecked" checked/>
<label class="form-check-label" for="flexCheckChecked">Aceito as políticas de privacidade</label>
</div>
<input type="submit" value="Validate!" />
</form>
</div>
<div class="container pt-2" id="containerJuridica">
<form id="formJuridica">
<div class="form-group pt-2 pb-2">
<label for="exampleInputEmail1">Razão Social</label>
<input type="text" class="form-control" id="razaoSocial" aria-describedby="emailHelp" placeholder="Razão Social" required>
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputPassword1">CNPJ</label>
<input type="number" class="form-control" id="cnpj" placeholder="Insira seu CNPJ">
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputPassword1">DDD</label>
<input type="number" class="form-control" id="dddJuridica" placeholder="DDD">
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputPassword1">Telefone</label>
<input type="number" class="form-control" id="telJuridica" placeholder="Número de telefone">
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputEmail1">E-mail</label>
<input type="email" class="form-control" id="emailJuridica" aria-describedby="emailHelp" placeholder="Insira seu e-mail">
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputEmail1">Confirmar E-mail</label>
<input type="email" class="form-control" id="confEmailJuridica" aria-describedby="emailHelp" placeholder="Confirme seu e-mail">
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputPassword1">Senha</label>
<input type="password" class="form-control" id="senhaJuridica" placeholder="Insira sua senha">
</div>
<div class="form-group pt-2 pb-2">
<label for="exampleInputPassword1">Confirmar Senha</label>
<input type="password" class="form-control" id="confSenhaJuridica" placeholder="Confirme sua senha">
</div>
<div class="form-check pt-2">
<input type="radio" class="form-check-input" id="aceitoEmailJuridica">
<label class="form-check-label" for="aceitoEmailJuridica">Aceito receber e-mails</label>
</div>
<div class="form-check pt-2">
<input type="radio" class="form-check-input" value="" id="flexCheckChecked" checked>
<label class="form-check-label" for="flexCheckChecked">Aceito as políticas de privacidade</label>
</div>
<input type="submit" value="Validar">
</form>
</div>
<script src="./validation.js" type="text/javascript"></script>
<script src="./script.js" type="text/javascript"></script>
Hello so Im fairly new to e2e testing and one of the things I want to test is when I change the shipping address I also want to set it to the billing address. So for instance if I set the Grove Street as my shipping address in the input field I also want it to be the same for the billing address. Is there a way for me to check the billing address as well as the shipping address that way
Here is my component:
const Delivery: React.FC<DeliveryProps> = ({ data})
and that data is modeled like this
data = {
...some other data
shippingAddress:string;
billingAddress:string;}
So in conclusion what I would like to do is fill the address field like so:
await checkout.verifyAddressInputField(page).fill('Grove street');
And to check the props value of my whole component aka the data props mainly shippingAddress and billingAddress
Any help would be great, thanks in advance
Is there a way to top align all the cells in excel when using export feature of datatables? I am able to wrap the text in excel as well as I have marked “stripNewlines” as false. It works, however the cells are bottom aligned, so it is very hard for the user to read. Is there a way to top align the cells? Thanks.
Here is my code:
customize: function( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row c[r^="B"]', sheet).attr( 's', '55' );
$('row c[r^="C"]', sheet).attr( 's', '55' );
$('row c[r^="A"]', sheet).attr( 's', '55' );
$('row c[r^="D"]', sheet).attr( 's', '55' );
$('row c[r^="E"]', sheet).attr( 's', '55' );
$('row c[r^="F"]', sheet).attr( 's', '55' );
$('row:nth-child(2) c', sheet).attr('s', '2');
$('row:nth-child(1) c', sheet).attr( 's', '2' );
$('row c[r^="A1"]', sheet).attr( 's', '51' );
},
exportOptions: {
columns: ':visible',
stripNewlines: false
}
},