Skip to main content

Posts

How to I create a simple countdown timer for 10 minutes without setInterval()

I want to create a simple countdown timer for 10 minutes. I have figured out how to do this for the most part but with setInterval() it seems to stop with 2 seconds left every time. I have heard that setInterval() can be very unreliable but I don't know what else to do. I set the timer to 1 minute and the seconds reset to 3 instead of 59 for time-saving purposes with running the code. const value = document.querySelector("#time"); const startBtn = document.querySelector("#btn-start") const resetBtn = document.querySelector("#btn-reset"); startBtn.addEventListener('click', function(){ var minute = 1; var sec = 3; setInterval(function(){ value.innerHTML = minute + ":" + sec; sec--; if(sec < 0){ minute--; sec = 3; } if(sec <=9){ sec = "0" + sec; } if(sec == 0 && minute == 0){ alert("DONE!&q

How to span active on click in javascript

I'm trying to make a span move into another span on click. When I use the function in the onclick event in JavaScript, it's not working. But, when I use the same function in html with a tag, it works. ..................................................................... Anything wrong with my code or what? var LoginForm = document.getElementById("LoginForm"); var RegisterForm = document.getElementById("RegisterForm"); var Indicator = document.getElementById("Indicator"); function register() { RegisterForm.style.transform = "translateX(0px)"; LoginForm.style.transform = "translateX(0px)"; } function login() { RegisterForm.style.transform = "translateX(300px)"; LoginForm.style.transform = "translateX(300px)"; } .account-page { padding: 50px 0; background: radial-gradient(#fff, #ffd6d6); } .form-container { background: #fff; width: 300px; height: 400px; position: relative; text-al

How to clean an array from empyu objects in mongodb?

Afterwards an aggregation in mongodb I get this results: [ my_arr:[ { id: ObjectId('618f7ef057c2923be10d1111') //other stuff }, {}, {}, ] ] Is there a way to remove the empty object directly in the aggregation? or it is necessary to do it server side? I get that after doing an unwind and a group. Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

How can i display my json data on html page

i want to display the json data the user has put in, but it isn't showing anything. when i press the button nothing happens. my json file is named varer.json. i want to show all the json data in a tabel when i press the button. I dont get an error, there is just nothing that happens, can it be something with the fetch??? please help here is my javascript function showData() { console.log("Showing Data") // var mainData = document.getElementById("jsonData"); // mainData.innerHTML="hello" fetch("varer.jsom") .then(response => { resp = response.json() return resp }) .then(resp => { appendData(resp) }) } function appendData(resp){ console.log(resp) var mainDiv = document.getElementById("jsonData"); for (i=0; i< resp.length; i++) { var nameDiv = document.createElement("div") nameDiv.className="collapsible"

Div not getting exact position onhover

I have a div and I want it to be shown at the exact same position as the hovered element inside the iframe . It gets the height and width correct tho, but not the top and left. What am I doing wrong? How to make it get the correct element position? Here's the code: <html> <body> <div> <div id="box"></div> <p id="a">You clicked on:</p> <iframe id="zzz" srcdoc="<html><h1>hello</h1><button> click </button></html>" width="500" height="500" ></iframe> </div> <script> let elem = ""; let myiframe = document.getElementById("zzz").contentWindow; let div = document.getElementById("box"); myiframe.addEventListener("mouseover", function (e) { elem = e.target; var rect = elem.getBou

Laravel and AWS SQS, How to read job payload / retrieve queue?

I struggling from last 3 days about how I can read queued job payload in Laravel. What I've achieved till yet. Dispatch a job and see that it is available on AWS SQS queue. After that I've executed listener and worker for AWS to process queued jobs and I see that it is working fine as well. Right now I am stuck on how I can read QUEUED job payload / messagebody / attributes from AWS SQS. Here is my code example if possible than anyone from this whole community please help me. <?php namespace App\Jobs; use App\CookieXrayConsentLog; use App\CookieXrayScript; use Carbon\Carbon; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Storage; class QueueC

MySQL update query in Wordpress plugin not working

I am developing a wordpress plugin but I am facing a problem. I would like to update an existing value of a table in a MySQL database. After some research, I saw that you can use this method: global $wpdb; $wpdb->query($wpdb->prepare("UPDATE myTable SET name=$name WHERE id=$idTable")); However when I run my code, I get this error in the javascript console: Uncaught Error: Call to a member function query() on null Do you have an idea how to solve this problem ? source https://stackoverflow.com/questions/70137262/mysql-update-query-in-wordpress-plugin-not-working