The vertical scrollbar of my website positions to left side abnormally. How can I fix it and set it to the right by default?
Category: javascript
Category Added in a WPeMatico Campaign
Solve Nim Game Leetcode with Recusion(DP)
I am trying to solve the following leetcode problem of Nim Game.
https://leetcode.com/problems/nim-game/
One simple solution in O(1) is:
var canWinNim = function(n) {
return n%4 !== 0;
};
But I am also trying to solve it using DP. Below is my code which is incorrect. I believe there is some issue in the else block at the end. Please help.
var canWinNim = function(n, myChance=true, memo={}) {
if(n in memo) return memo[n];
if(myChance){
if(n<=3) return true;
if(n===4) return false;
} else {
if(n<=3) return false;
if(n===4) return true;
}
let a = canWinNim(n-1, !myChance, memo);
let b = canWinNim(n-2, !myChance, memo);
let c = canWinNim(n-3, !myChance, memo);
if(myChance){
memo[n] = a||b||c;
return memo[n];
}
memo[n] = !(a||b||c);
return memo[n];
};
How to create dynamic table with rowspan in javascript
How to create a fully dynamic table with dynamic rowspan ?
My data will change according to user search and the data shown below is just a sample only.
Sample data and partially dynamic code is below I would like to make it fully dymnamic.
please help me to make it fully dynamic so that I can display the content efficiently.
<html>
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js" integrity="sha512-28e47INXBDaAH0F91T8tup57lcH+iIqq9Fefp6/p+6cgF7RKnqIMSmZqZKceq7WWo9upYMBLMYyMsFq7zHGlug==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.css" integrity="sha512-Fik9pU5hBUfoYn2t6ApwzFypxHnCXco3i5u+xgHcBw7WFm0LI8umZ4dcZ7XYj9b9AXCQbll9Xre4dpzKh4nvAQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<body>
<script>
$(document).ready(function(){
var data = [];
data[0] = ["text1","cat1","121 AA","50"];
data[1] = ["text1","cat1","125 BB","45"];
data[2] = ["text2","cat2","214 CC","27"];
data[3] = ["text3","cat3","245 KP","31"];
data[4] = ["text4","cat4","425 DD","43"];
data[5] = ["text4","cat4","111 CC","95"];
data[6] = ["text5","cat5","222 EE","64"];
data[7] = ["text6","cat6","425 FF","72"];
var htmls= "";
htmls = "<table class='table table-hover table-bordered'>"+
"<tr>"+
"<th>TITE 1</th>"+
"<th>TITE 2</th>"+
"<th>TITE 3</th>"+
"<th>TITE 4</th>"+
"</tr>";
for(var i=0;i<data.length;i++){
if(i==0 || i==1){
var i2 = 1+1;
htmls +="<tr>"+
"<td rowspan='2'>"+data[i][0]+"</td>"+
"<td rowspan='2'>"+data[i][1]+"</td>"+
"<td>"+data[i][2]+"</td>"+
"<td>"+data[i][3]+"</td>"+
"</tr>";
htmls +="<tr>"+
"<td>"+data[i2][2]+"</td>"+
"<td>"+data[i2][3]+"</td>"+
"</tr>";
i=i+1;
}
else if(i==4 || i==5){
htmls +="<tr>"+
"<td rowspan='2'>"+data[i][0]+"</td>"+
"<td rowspan='2'>"+data[i][1]+"</td>"+
"<td>"+data[i][2]+"</td>"+
"<td>"+data[i][3]+"</td>"+
"</tr>";
htmls +="<tr>"+
"<td>"+data[i+1][2]+"</td>"+
"<td>"+data[i+1][3]+"</td>"+
"</tr>";
i=i+1;
}
else{
htmls +="<tr>"+
"<td>"+data[i][0]+"</td>"+
"<td>"+data[i][1]+"</td>"+
"<td>"+data[i][2]+"</td>"+
"<td>"+data[i][3]+"</td>"+
"</tr>";
}
}
$("#htmls").html(htmls);
});
</script>
<div id='htmls'></div>
</body>
</html>
Auto copy x times a row or range when ‘recurrence’ cell = “Yes” and x is calculated within the sheet
I have a village hall booking system in Google Sheets, operating from google forms. I have a single row for each booking. When an enquiry says ‘yes’ to recurrence, I want to duplicate some details in the sheet to create further booking rows. I have a cell which calculates the number of bookings based on the dates/frequency.
My site just says 403 for bidden and i dont know what to do
really need help my site just say 403 forbidden and i don’t knoq qhat to do
How do I get my draggable elements to drag outside of a scroll box?
I have draggable elements that I’d like to scroll if they overflow the container, however, I also need these items to be draggable outside of the that scroll container.
This is my code so far. http://pastie.org/p/1QD6PUvYOGikOIcMxXQ2Lc
I’m currently working on the ‘tables’ section and right now it scrolls correctly, but the element can only drag freely within the container and not outside of it. I believe I need to do some cloning, but haven’t found a code that works yet.
Any help is so appreciated! Thank you!
react – function running two times
When I am opening below component then it is prinitng two times in innerhtml as shown in below picture
import React from 'react';
const bring_blogs = async ()=>{
const response = await fetch('http://localhost/get/blogs',{
method:'GET',
headers : {
'Content-Type' : 'application/json',
}
})
const json = await response.json()
const blogs = JSON.parse(json.blogs)
for(let i = 0; i<Object.keys(blogs).length ; i++){
var key = Object.keys(blogs)[i]
document.getElementById('blogs-container').innerHTML += `
<div className="srno">${i+1}</div>
<div className="title">${blogs[key][0]}</div>
<div className="desc">${blogs[key][1]}</div>
`
}
}
export const Blogs = (props) => {
props.changetitle('My Blogs')
bring_blogs()
return (
<>
<div className="blogs-container" id='blogs-container'>
<div className="srno"></div>
<div className="title"></div>
<div className="desc"></div>
</div>
</>
);
};
Can anyone please tell me why is this happening? thnx
How do I call RobinHerbots inputmask from sitepage.master and into a childpage with UpdatePanel?
I have tried to make use of RobinHerbots InputMask and inherited the functionality in my ASPX’s masterpage and it works nearly fine. But only on some of my child pages it works fine and shows the inputmask on hover and focus. On other ASPX-pages it does not show the inputmask on hover and focus. I have based my coding on this jsfiddle: https://jsfiddle.net/sotosamper1234/7vddjcwu/
I think that it has something to do with my UpdatePanel which I have used in the childpages where it doesn’t work.
I have googlet a lot without finding the answer until now 🙁
I have have called the RobinHerbots library in this way:
<script type="text/javascript" src="Inputmask-5.x/jquery.js?v="+<%# DateTime.Now.ToString("ddMMyyyyhhmmss") %> ></script>
<script type="text/javascript" src="Inputmask-5.x/dist/jquery.inputmask.js?v="+<%# DateTime.Now.ToString("ddMMyyyyhhmmss") %> ></script>
And I have called the alias in this way:
<asp:TextBox ID="txtAddADate" runat="server" Text="" Width="150px" data-inputmask="'alias': 'FreEconomic-datetime'"></asp:TextBox>
And my Javascript in my MasterPage’s SCRIPT section look like this:
var customInputmask = (function () {
var config = {
extendDefaults: {
showMaskOnHover: true,
showMaskOnFocus: true
},
extendDefinitions: {},
extendAliases: {
'FreEconomic-datetime': {
alias: "datetime",
inputFormat: "dd.mm.yyyy"
},
'FreEconomic-decimal': {
alias: 'currency',
prefix: '',
radixPoint: ',',
groupSeparator: '.',
autoGroup: false,
}
}
};
var init = function () {
Inputmask.extendDefaults(config.extendDefaults);
Inputmask.extendDefinitions(config.extendDefinitions);
Inputmask.extendAliases(config.extendAliases);
$('[data-inputmask]').inputmask();
};
return {
init: init
};}());
$(document).ready(function () {
customInputmask.init();}());
So my question is what I have to do for making the inputmask visible on hover and on focus on all my child pages inherited from SitePage.Master? And because of my usage of UpdatePanel – is there something I can do in Javascript/Script-TAG of the MasterPage for activating RobinHerbots inputmask in the childpages where the TextBox is wrapped into an UpdatePanel?
I am very new to javascript – so maybe there is something which for me is new to learn.
Thanks in advance,
Michael
CSS Button animations in HTML
I have the following code:
var basicTimeline = anime.timeline({
autoplay: false,
});
var pathEls = $(".check");
for (var i = 0; i < pathEls.length; i++) {
var pathEl = pathEls[i];
var offset = anime.setDashoffset(pathEl);
pathEl.setAttribute("stroke-dashoffset", offset);
}
basicTimeline
.add({
targets: ".text",
duration: 1,
opacity: "0"
})
.add({
targets: ".button",
duration: 1300,
height: 20,
width: 81,
backgroundColor: "#717F7E",
border: "0",
zIndex: 0,
borderRadius: 100
})
.add({
targets: ".progress-bar",
duration: 2000,
width: 81,
easing: "linear"
})
.add({
targets: ".button",
width: 0,
duration: 1
})
.add({
targets: ".progress-bar",
width: 40,
height: 39,
delay: 500,
duration: 750,
borderRadius: 80,
backgroundColor: "#71DFBE",
left: 20
})
.add({
targets: pathEl,
strokeDashoffset: [offset, 0],
duration: 200,
easing: "easeInOutSine"
});
$(".button").click(playButtonAnim);
$(".text").click(playButtonAnim);
function playButtonAnim() {
basicTimeline.play();
}
//error animation
const form = document.forms.myform;
form.onsubmit = e => {
e.preventDefault()
let data = Object.fromEntries(new FormData(form).entries())
console.log(data)
let validationOK = true
for (let entrie in data) {
if (!form[entrie].checkValidity()) {
validationOK = false
form[entrie].classList.add('shakingErr')
setTimeout(() => {
form[entrie].classList.remove('shakingErr')
}, 820)
}
}
if (validationOK) {
fetch(form.action, {
method: form.method,
body: JSON.stringify(data),
headers: {
Accept: 'application/json'
}
})
.finally(() => {
window.location = "thankyou.html"
})
}
}
/* Contact Form */
input[type=text],
[type=email],
select,
textarea {
width: 100%;
padding: 12px;
border: 1px solid #555;
margin-top: 6px;
margin-bottom: 16px;
resize: vertical;
}
input[type="text"]:focus,
input[type="email"]:focus,
#subject:focus {
background: var(--bgFormElsFocus);
transform: scale(1.02);
transition: transform 0.2s ease-in-out;
}
.contactform {
position: relative;
border-radius: 50px;
background-color: #f2f2f2;
padding: 5px;
z-index: 2;
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: auto;
margin-top: 1%;
width: 100%;
animation-name: gradient;
animation-duration: 3s;
animation-iteration-count: infinite;
}
.contactform:hover {
animation-name: gradient;
animation-duration: 15s;
animation-iteration-count: infinite;
}
.column {
float: center;
width: 50%;
margin-top: 6px;
padding: 20px;
display: block;
margin-left: auto;
margin-right: auto;
}
.row:after {
content: "";
display: table;
clear: both;
}
@media screen and (max-width: 600px) {
.column,
input[type=submit] {
width: auto;
margin-top: 0;
}
}
.shakingErr {
border-color: red;
animation: shake 0.82s forwards;
}
@keyframes shake {
10%,
90% {
transform: translate3d(-1px, 0, 0);
}
20%,
80% {
transform: translate3d(2px, 0, 0);
}
30%,
50%,
70% {
transform: translate3d(-4px, 0, 0);
}
40%,
60% {
transform: translate3d(4px, 0, 0);
}
}
/* fancy button styles */
.buttonWrapper {
height: 39px;
width: 81px;
position: relative;
}
.button {
background: #2B2D2F;
height: 39px;
width: 81px;
text-align: center;
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 0;
cursor: pointer;
border-radius: 4px;
z-index: 10;
}
.text {
font: .8rem/1 poppins;
color: #71DFBE;
position: absolute;
top: 50%;
transform: translateY(-52%);
left: 0;
right: 0;
cursor: pointer;
}
.progress-bar {
position: absolute;
height: 20px;
width: 0;
left: 40px;
top: 50%;
border-radius: 200px;
transform: translateY(-50%) translateX(-50%);
background: black;
}
svg {
width: 15px;
position: absolute;
top: 50%;
left: 20px;
transform: translateY(-50%) translateX(-8px);
}
.check {
fill: none;
stroke: #FFFFFF;
stroke-width: 3;
stroke-linecap: round;
stroke-linejoin: round;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>replit</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="https://fonts.googleapis.com/css?family=Poppins:600" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Poppins:600" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.js">
</script>
</head>
<body>
<!-- start contact section -->
<section id="contact">
<div class="container" data-aos="fade-up">
<div class="contactform">
<div style="text-align:center">
<div class="section-title">
<h2><br />Get In Touch</h2>
</div>
<p>Feel Free To Reach Out To Me Through This Form! </p>
</div>
<div class="row">
<div class="column">
<form name="myform" action="https://formspree.io/f/xrg123232jbqpq" id="my-form" method="POST" novalidate>
<label for="firstname">First Name</label>
<input type="text" id="first name" name="firstname" placeholder="Your First Name.." required>
<label for="lastname">Last Name</label>
<input type="text" id="lastname" name="lastname" placeholder="Your Last Name.." required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Your Email.." required>
<label for="subject">Subject</label>
<textarea id="subject" name="subject" placeholder="Lets Collaborate.." style="height:170px" required></textarea>
<!-- <input type="submit" value="Submit"> -->
<div class='buttonWrapper'>
<div class="button">
<div class="text">Submit</div>
</div>
<div class="progress-bar"></div>
<svg x="0px" y="0px" viewBox="0 0 25 30" style="enable-background:new 0 0 25 30;">
<path class="check" class="st0" d="M2,19.2C5.9,23.6,9.4,28,9.4,28L23,2" />
</svg>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<script src="script.js"></script>
</body>
</html>
The only problem I’m facing is that even though I have error animation code in the JS that calls in the shakingErr
class from CSS if there are empty fields and the user tries to click the submit button, the animation seems to be not working. How can I make it so that when the user clicks the submit button, the contact form has a shaking error button.
Notice that when you click the submit button, there is also an animation that plays on the button? I would not like that animation to play when the user clicks submit button on empty fields. I would only like the animation to play once the user has filled all the information in the input fields.
Any suggestions?
EXPECTED OUTPUT
https://watch.screencastify.com/v/D2VXp3493XZXl3Lmh7yR
As you can see, whenever the user tries to click submit button on empty/wrong fields (Email) then the error animation plays. Also, the button animation should not play when the user clicks the submit button on empty/wrong fields. It should play once the fields are filled and are right.
What I tried
So I had another submit button before this one, and I was able to have the shaking error animation working, but its a bit different for this button. The previous button had a class input[type=submit]
and this seemed to work well, as the animation worked when I used the html: <input type="submit" value="Submit">
. How can I make the animation work now?
Losing the value of this keyword when using it with instance level variables in a class in javascript
I have two classes one of them is the parent class and the other one is the child class and what I’m trying to achieve is to access the values of child classe’s instance level variables by using this
keyword in a field that is declared in the parent class. But when I try to do so it returns undefined
. Can anyone please explain what might be going wrong here. Below I’ve pasted a code snippet for your reference. Thanks!
class Parent {
someField = {
someValue: 'Values are ::: '+ this.value1 + ' ' + this.value2,
childType2: "Some gibberish"
}
initialize(childType1) {
this.someField = this.someField[childType1];
}
}
class Child extends Parent {
value1 = "someValue 1"
value2 = "someValue 2"
}
const child = new Child();
child.initialize("someValue");
console.log(child.someField);
Can I add any element to another HTML file when I click current submit button?
I’m creating a blog website for myself to take notes about my experiences, etc. I prepared HTML and CSS files. When I click “share” button, text is being sent to MySQL database and it can be shown on the main page. But I want to add a new div element on main page by clicking “share” button. How can I do that?
how to not add a user if it exists in a form react.js
so i have the problem where i have the form a phonebook and i add people in it but the task is whenever i try add the user that is already in there it must not let me do it and throw an error this person is already in a phonebook i dont want only solution i want explanation if anyone can explain it to me how to solve it and how it works code:
import React, { useState } from 'react'
import Person from './Person'
const App = () => {
const [persons, setPersons] = useState([
])
const [newName, setNewName] = useState('')
const handleNoteChange = (event) => {
setNewName(event.target.value)
}
const resetForm = () => {
setNewName('')
}
const handleSubmit = (e) => {
e.preventDefault()
const persona = {
name: newName,
id:Math.floor(Math.random() * 10000)
}
setPersons(persons.concat(persona))
setNewName('')
persons.map(perperson =>{
if(perperson.name === newName){
alert(`${newName} is already in the phonebook `)
}
})
console.log(persona);
}
return (
<div>
<h2>Phonebook</h2>
<form onSubmit={handleSubmit}>
<div>
name: <input
value={newName}
onChange={handleNoteChange}
/>
</div>
<div>
<button type="submit">add</button>
</div>
</form>
<h2>Numbers</h2>
<ul>
{persons.map(person => {
return(
<Person key={person.id} name={person.name} />
)
})}
</ul>
<p onClick={resetForm}>reset input</p>
<p>phonebook name is - {newName}</p>
</div>
)
}
export default App
Person component:
import React from 'react';
const Person = (props) => {
return(
<div>
<li key ={props.id}>{props.name}</li>
</div>
)
};
export default Person;
function not properly processing form data in Google Apps Script
Working on a Google Sheets Script I created that has stopped working.
It appears that the form may not be feeding the function properly, but I’m not sure why.
This part of the script is intended to be sure that the user has entered a user ID and an item ID for checkout.
form:
<div class="inline form-group">
<label for="uid">User ID</label>
<input type="text" name="chkOutUID" id="uid" value="" size="6"></div>
<div class="inline form-group">
<label for="iid">Item ID</label>
<input type="text" name="chkOutIID" id="iid" value="" size="6"></div>
function:
function confirm(uid,iid,datepicker) {
if((uid=="" && iid=="") || (uid=="" || iid=="")) {
ui.alert("You must enter User ID and Gear ID");
} else {
var userID=uid.toString();
var itemID=iid.toString();
var enteredDate = new Date(datepicker);
var dueDate;
//if(datepicker="click to choose date") {
if (Object.prototype.toString.call(enteredDate) !== "[object Date]") {
Logger.log("is not a date");
var defaultDue = new Date();
var defaultDueDate =defaultDue.getMonth()+1+"/"+defaultDue.getDate()+"/"+defaultDue.getYear();
dueDate=defaultDueDate;
} else {
var enteredDue = new Date(enteredDate);
var dueDate = enteredDue.getMonth()+1+"/"+enteredDue.getDate()+"/"+enteredDue.getYear();
}
}
Error called is Type Error: Cannot call method “toString” of undefined
make the checkbox single choice
I want to apply this code on vuejs
I replaced onclick by @click but it doesn’t work!
ps: I’m beginner on vuejs
function onlyOne(checkbox) {
var checkboxes = document.getElementsByName('check')
checkboxes.forEach((item) => {
if (item !== checkbox) item.checked = false
})
}
<input type="checkbox" name="check" onclick="onlyOne(this)">
<input type="checkbox" name="check" onclick="onlyOne(this)">
<input type="checkbox" name="check" onclick="onlyOne(this)">
<input type="checkbox" name="check" onclick="onlyOne(this)">
How to use th:each to pass a string to JavaScript code embedded in html page
I start by creating a test list with links to an image.
Then I pass it to the model under the name _links
@GetMapping("/{id}")
public String showItem(@PathVariable int id, Model model)
{
List<String> imageLinks = new ArrayList<>();
imageLinks.add("/resources/static/images/products/1/product_test_image.jpg");
imageLinks.add("/resources/static/images/products/1/product_test_image2.jpg");
imageLinks.add("/resources/static/images/products/1/product_test_image3.jpg");
model.addAttribute("_links", imageLinks);
return "item/item";
}
Then, at a certain place in the html code, I draw the number of buttons equal to the number of pictures in the _links list.
I can pass the cycle number to the imgSrc method. But I can’t pass the link string itself. When I try to send it, the page stops displaying normally. Therefore, this line is commented out.
<div th:each="link, iStat : ${_links}">
<span id="current_img" th:text="${link}"></span>
<input type="image" th:src="${link}" alt="miniature" th:onclick="'imgSrc('' + ${iStat.index} + '');'" style="width: 80px; height: 80px; margin: 3px">
<!-- <input type="image" th:src="${link}" alt="miniature" th:onclick="'imgSrc('' + ${link} + '');'" style="width: 80px; height: 80px; margin: 3px"> -->
</div>
And finally the method I’m calling. The last line is commented out but it shows what I want to achieve.
Namely, by clicking on the picture in the list, I want to change the large picture to the new one selected in the loop.
<script language="JavaScript">
var selectedImage = document.getElementById("current_img");
var mainImage = document.getElementById("main_product_image");
var debug = document.getElementById("debug");
var debug2 = document.getElementById("debug2");
function imgSrc(link)
{
mainImage.src = selectedImage.innerHTML;
debug.innerHTML = selectedImage.innerHTML;
debug2.innerHTML = link;
// mainImage.src = link;
}
</script>
Thanks in advance to all who answer.