r/JavaScriptHelp • • Jul 03 '21

❔ Unanswered ❔ Typescript frameworks/packages for blitz.js

1 Upvotes

I started working on a project with Blitz.js. I'd like to add an admin panel to it, and was looking at react-admin. I know the project is going to be mainly typescript, SQLite and Postgres with API support. Is is possible to combine the react-admin with the authentication, API, and DB that blitz.js provides? Is there a tutorial on how to achieve something like this? Or is there a better dashboard template I can follow to achieve the same result with less effort?


r/JavaScriptHelp • • Jul 13 '21

❔ Unanswered ❔ Press enter at end of function

3 Upvotes

Hey guys,

A quick question that I hope someone can help out with.

I've got a simple function that enters a string into an input:

$(document).ready(function(){
$("#asset_return a").click(function(){
var value = $(this).html();
var input = $('#search_text');
input.val(value);
var focus = $('#search_text').focus();
var submit = $('#search_text').submit();
});
});
</script>

What I need it to do is press enter at the end of the function - I tried submit but to no avail. Any ideas?


r/JavaScriptHelp • • Jul 11 '21

✔️ answered ✔️ .contains is not a function

1 Upvotes

Edit:

const UN = urlParams.get('username'); const check = UN.toString(); if(check.includes(" ")){ window.location.href = "URL Removed" }

I'm trying to redirect the user if their username contains a space, but I'm getting

Uncaught TypeError: check.contains is not a function

as a result my code:

const UN = urlParams.get('username'); const check = UN.toString(); if(check.contains(" ")){ window.location.href = "URL Removed" }

r/JavaScriptHelp • • Jul 30 '21

❔ Unanswered ❔ How do I stop the page from refreshing after submit?

1 Upvotes

I want to create a function similar to live messaging apps where the page does not refresh when a user sends a message. This is my js code so far:

setTimeout(function(){
		messages_holder.scrollTo(0,messages_holder.scrollHeight);
		var message_text = _("message_text");
		message_text.focus();
	},100);

	function send_message(e)
	{
		var message_text = _("message_text");
	}

	function enter_pressed(e)
	{
		if(e.keyCode == 13)
		{
			send_message(e);
		}
	}

This is where I want to include the function in my HTML code:

<input id="message_text" onkeyup="enter_pressed(event)" name="message" placeholder="Type a message...">
														<label for="inpFile"><img id="image_icon" src="http://localhost/mybook/images/images_icon.png" style="left:30px;top:7px;"></label>
														<input id="inpFile" type="file" name="file" style="display:none;" accept="image/*">
 								 						<input id="post_button" type="submit" value="Send" onclick="send_message(event)" style="margin:5px;display:none;">

If you need more information please let me know. Any help would be greatly appreciated!


r/JavaScriptHelp • • Aug 06 '21

❔ Unanswered ❔ Ball Won't Move! Help?

1 Upvotes

Trying to do my coding homework on khan academy and I'm supposed to make a ping pong type game where the ball bounces around the right side rectangle and it should wobble when it bounces and add a new ball every 30 seconds. It is supposed to start with 5 balls in an array. I am using two other projects I worked on with arrays and having the balls bounce, but neither is giving me the answers. Here is my code (I apologize if im unable to post it this way i just need help!)

I need help with: Getting the ball to move

Showing more than one ball (array of five)

Adding a ball every 30 seconds

var screen = function({)

strokeWeight(3;)

stroke(107, 107, 107;)

fill(179, 179, 179;)

rect(120,1,278,397;//right)

fill(71, 71, 71;)

rect(1,1,119,397;//left)

fill(36, 36, 36;)

rect(1,314,119,84;//score)

fill(255, 0, 0;)

textSize(20;)

text("SCORE",24,321,100,50;)

};

var x = 120; //top

var y = 1;//bottom

var w = 278; //left

var h = 397; //right

var xpos = [];

var ypos = [];

var xspd = [];

var yspd = [];

var cB = [];

var b = 20;

var balls = function({)

for(var i = 0 ; i < 5 ; i++{)

xpos.push(0;)

ypos.push(random(30,370;))

cB.push(color(random(255,random(255,random(255)));))

}

};

var ball = function(x,y,c{)

strokeWeight(1;)

fill(c;)

translate(x,y;)

ellipse(0,0,5,5;)

resetMatrix(;)

};

balls(;)

draw= function( {)

screen(;)

translate(200,200; //Just to see the ball)

for(var i = 0; i < 5 ; i++{)

var x = xpos[i];

var y = ypos[i];

var c = cB[i];

ball(x,y,c;)

xpos += xspd;

ypos += yspd;

xspd = random(-3,3;)

yspd = random(-3,3;)

if(xpos < w + b/2 {)

xpos = w + b/2;

xspd *= -1;

}

if(xpos > h - b/2 {)

xpos = h - b/2;

xspd *= -1;

}

if(ypos < x + b/2 {)

ypos = x + b/2;

yspd *= -1;

}

if(ypos > y - b/2 {)

ypos = y - b/2;

yspd *= -1;

}

}

};


r/JavaScriptHelp • • Jul 17 '21

💡 Advice 💡 JS & Typescript stuggle

2 Upvotes

Names Edgar, 44. Been manual QA for 12 years. Laid off during COVID after 7 years. Company made more money than ever during COVID. I'm now taking Test Automation Software bootcamp at DevMountain.

For the freaking life of me I am having an unbelievably and extremely difficult time retaining any code I'm being taught. I'm a bit dyslexic and also very hands on guy.

I'm struggling so much I had a breakdown tonight due to the fact I just have such a hard time retaining it then applying it appropriately.

I can use Sololearn pretty well to "answer" questions and do really well at questions and answers. But when I have to write/type things out appropriately I immediately draw a blank and it's as off my brain fills up with sand.

My environment is quiet, I listen to calm study music, jot down key things but then when I have to create code correctly in the right or at the appropriate place my brains hits a major roadblock.

It's so stressful now, I'm behind a unit and half. I'm extremely embarrassed with myself.

Any videos, books, sites that can help me retain it in a way "Explain it like I'm 5" method.

I'm using VSCODE with node.js and it's also typescript.

Maybe a volunteer tutor group that would help me over zoom when I'm not in class. My school schedule is 6-9pm MST M-W and Sat 9AM-12PM.

I'm about to give up wasting $5000 loan because I feel it's not sinking in yet. Feels like I'm destined to be stuck jobless as a manual QA and companies want mostly Automation now.

New to the community. Thank you all for your time.

It's 4:08am and have class at 9AM. Freaking brain won't turn off because of constant worry of failure. Need a couple hours sleep before class.

Cheer!


r/JavaScriptHelp • • Jul 01 '21

❔ Unanswered ❔ Beginner here - can someone translate into approximate logic what this bit of js is doing?

2 Upvotes

I just really can't understand it..

var t = e.filter(function(e) {

return null != e

});

return 20 < t.length ? t.slice(0, 20) : t


r/JavaScriptHelp • • Jul 13 '21

❔ Unanswered ❔ timeStyle: "short" equivalent that works in all browsers?

1 Upvotes

I have a timestamp like this: 2021-07-23T23:35:00

var myDate = new Date("2021-07-23T23:35:00").toLocaleTimeString("en-US", { timeStyle: "short" }).toLowerCase();

Chrome will give me (correctly):

11:35 pm

IE11 gives me:

‎. 11‎:‎35‎:‎00‎ ‎pm

Safari gives me:

07:35 pm

I've boiled it down to timeStyle: "short".

Is there a way to get this with other toLocaleTimeString options?

Thanks!


r/JavaScriptHelp • • Jun 25 '21

💡 Advice 💡 Not show the time/seconds until ‘record’ starts on html5 player

1 Upvotes

This code allows the page vistor to click a ‘display’ button to show the camera view on the page, but not start the video recording (they can select a seperate ‘record’ button to start recording). However, the timer/seconds start upon selecting ‘display’ the camera view. I’d like help with having the time/seconds not start until ‘record’ button is clicked. Any help/guidance is appreciated. Here’s the code:

let blobs = [];
let stream, mediaRecorder, blob;

let video = document.getElementById("video");
var displaying = false;
var recording = false;
async function display() {
  stream = await navigator.mediaDevices.getUserMedia({
    audio: true,
    video: true,
  });
  video.srcObject = stream;
  displaying = true;
}
function startRecording() {
  if(displaying){
    mediaRecorder = new MediaRecorder(stream);
    mediaRecorder.ondataavailable = (event) => {
    // Let's append blobs for now, we could also upload them to the network.
      if (event.data) {
        blobs.push(event.data);
      }
    };
    mediaRecorder.onstop = doPreview;
    // Let's receive 1 second blobs
    mediaRecorder.start(1000);
    recording = true;
  }
}

function endRecording() {
  if(recording){
    // Let's stop capture and recording
    mediaRecorder.stop();
    stream.getTracks().forEach((track) => track.stop());
    recording = false;
  }
}

function doPreview() {
  if (!blobs.length) {
    return;
  }
  // Let's concatenate blobs to preview the recorded content
  blob = new Blob(blobs, { type: mediaRecorder.mimeType });
  video.srcObject = null;
  video.src = URL.createObjectURL(
    blob,
  );
}

Here is the html:

<video id="video" autoplay controls muted playsInline></video>
<button id="display" onclick="display()">Display Camera</button>
<button id="start" onclick="startRecording()">Start Recording</button>
<button id="stop" onclick="endRecording()">Stop Recording</button>

And here is an example:

https://codepen.io/pmw57/pen/LYWwOZj

it was suggested that I should remove the video controls from the video first and then add them back when the recording starts., but I don't know how to do that.

any help is appreciated.


r/JavaScriptHelp • • Jun 28 '21

❔ Unanswered ❔ Sql comment with a ' in the middle of it is stopping me from creating a string out of it

2 Upvotes

So I'm trying to get a comment from sql and put it into a js array, but it's giving me errors because it's built like this: "This is ' a comment", and so the second part becomes a non-string. And when trying to toString() the whole comment, the toString() method just becomes part of the string.


r/JavaScriptHelp • • Jul 22 '21

❔ Unanswered ❔ Creating an email signature generator

Thumbnail self.learnjavascript
1 Upvotes

r/JavaScriptHelp • • Jun 30 '21

💡 Advice 💡 Any way to compress a cached file?

2 Upvotes

I have a successfully working page where a visitor can record a video via html5 < video > via web cam. Once it's recorded it automatically Plays the just recorded video (and then can be uploaded).Because it takes too long to upload, is there any way to compress or zip the browser cached (recorded) file, prior to upload, to help improve the upload speed?


r/JavaScriptHelp • • Jul 23 '21

❔ Unanswered ❔ How to preview the video file that user wants to upload on the website

1 Upvotes

I want to show a preview of uploaded video file before submit. I have successfully done this with an image thanks to the following JS, but it is not working with video files...

textarea = document.querySelector("#autoresizing");
  textarea.addEventListener('input', autoResize, false);

  function autoResize() {
      this.style.height = 'auto';
      this.style.height = this.scrollHeight + 'px';
  }

  const inpFile = document.getElementById("inpFile");
  const previewContainer = document.getElementById("imagePreview");
  const originalImage = document.getElementById("originalImage");
  const previewImage = previewContainer.querySelector(".image-preview__image");

  inpFile.addEventListener("change", function() {
    const file = this.files[0];

    if (file) {
      const reader = new FileReader();

      previewContainer.style.display = "block";
      previewImage.style.display = "block";
      originalImage.style.display = "none";

      reader.addEventListener("load", function() {
        previewImage.setAttribute("src", this.result);
      });

      reader.readAsDataURL(file);
    }else{
      previewImage.style.display = null;
      previewImage.setAttribute("src","");
    }
  });

r/JavaScriptHelp • • Jul 10 '21

💡 Advice 💡 How to be proficient in using Javascript for Web development?

2 Upvotes

Hi Guys!

I recently covered almost all parts of HTML and CSS. I've made loads of projects and confident enough to create a fully responsive web page like landing page, portfolio website, etc.

Now I'm stepping into the world of JS. I'm able to understand and use DOM, Event Handling, and arrays by building small projects. But now I'm unable to understand **objects, prototypes, OOPs concepts like classes, async and await, promises, etc** which is crucial for learning JS libraries like React(my next learning path), Angular, and Vue.

I don't know how and where we'll use these object property and OOPs concepts which stops me from building new projects.

So can you please provide me resources or guidance to understand and build projects using the above-mentioned JavaScript concepts so that I can be fluent enough to learn React and node.js?

Any form of advice, guidance, tutorial, or book recommendation with a proper plan or learning path to excel in those concepts will be much helpful to ace my frontend development skills.

Thanks in advance!


r/JavaScriptHelp • • Dec 07 '12

fancybox help

1 Upvotes

Hi!

I think, this is the best place to post this (since both ajax and jquery are based on javascript). So I've tried to create a login popup window with fancybox and it works based on this.

But could, please someone shed some light on how to make it work with ajax, to actually log the user in with the data compared to the mysql database? (and to close the popup window after)

Thanks


r/JavaScriptHelp • • Mar 03 '21

❔ Unanswered ❔ Looking for little direction/guidance re: iterating arrays.

1 Upvotes

New to JS. I'm doing a project where We created a "widgetPlan" which contains 4 arrays, one parent then children in one .js file. In another .js file I've been instructed to create a function which will accept that plan as a parameter and iterate through all of the arrays. I've been looking through the different array iteration methods and was just looking for some guidance on which method would be most helpful to my task before I just started trying all of them and seeing what stuck to the wall. (Hope that made sense)


r/JavaScriptHelp • • Mar 08 '21

💡 Advice 💡 show placeholder until image is loaded (getuikit)

1 Upvotes

Trying to make a carousel that would only load the images when they are to be displayed. So anything off-screen is not loaded yet. However, sometimes this is slow, so you end up seeing white where the image should be until it's loaded. I want to use a placeholder instead, can't get it to work though. Something like…

<div class="uk-slider-container">
    <ul class="uk-slider-items uk-grid-small>
    <?php foreach ($images as $image) : ?>
        <li>
        <img data-src="<?=$image->url;?>" background="images/placeholder.svg" uk-img>
        </li>
    <?php endforeach; ?>
    </ul>
</div>

or do I use datasrcset? datascrc? None of that stuff seems to do what I want.

Here's the documentation: https://getuikit.com/docs/image#target

thanks for input


r/JavaScriptHelp • • Mar 01 '21

❔ Unanswered ❔ Help me understand this javascript code

1 Upvotes

Actually i am a complete beginner in javascript and was trying to make a javascript calculator and after seeing this js code i got totally confused.

Javascript code ->

(function(){

let screen = document.querySelector('.screen');

let buttons = document.querySelectorAll('.btn');

let clear = document.querySelector('.btn-clear');

let equal = document.querySelector('.btn-equal');

//retrieve data from numbers that are clicked

buttons.forEach(function(button){

button.addEventListener('click', function(e){

  let value = e.target.dataset.num;

  screen.value += value;
})

});

equal.addEventListener('click', function(e){

if(screen.value === ''){

  screen.value = 'Please Enter a Value';

} else {

  let answer = eval(screen.value);

  screen.value = answer;

}

})

clear.addEventListener('click', function(e){

screen.value = '';

})

})();

And this is the Html part ->

<!DOCTYPE html>

<html lang="en">

<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Recording</title> </head>

<body>

<section class="calculator">

<form>

<input type="text" name="" id="" class="screen">

</form>

<div class="buttons">

<!-- yellow -->

<button type="button" class="btn btn-yellow" data-num="*">*</button>

<button type="button" class="btn btn-yellow" data-num="/">/</button>

<button type="button" class="btn btn-yellow" data-num="-">-</button>

<button type="button" class="btn btn-yellow" data-num="+">+</button>

<!-- grey buttons -->

<button type="button" class="btn btn-grey" data-num=".">.</button>

<button type="button" class="btn btn-grey" data-num="9">9</button>

<button type="button" class="btn btn-grey" data-num="8">8</button>

<button type="button" class="btn btn-grey" data-num="7">7</button>

<button type="button" class="btn btn-grey" data-num="6">6</button>

<button type="button" class="btn btn-grey" data-num="5">5</button>

<button type="button" class="btn btn-grey" data-num="4">4</button>

<button type="button" class="btn btn-grey" data-num="3">3</button>

<button type="button" class="btn btn-grey" data-num="2">2</button>

<button type="button" class="btn btn-grey" data-num="1">1</button>

<button type="button" class="btn btn-grey" data-num="0">0</button>

<button type="button" class="btn-equal btn-grey">=</button>

<button type="button" class="btn-clear btn-grey">C</button>

</div>

</section>

</body>

</html>


r/JavaScriptHelp • • Mar 09 '21

❔ Unanswered ❔ sprite.getFrames()

1 Upvotes

so i'm making a game on code.org and theres a part where i want to play an animation (so it would cycle through the frames of a gif). my problem, though, is that i want the animation to, you know, end at some point, but i can't really do that because the sprite.getFrame() function doesn't exist anymore. does anyone know a workaround for this? i can attach my code if necessary.


r/JavaScriptHelp • • Mar 17 '21

❔ Unanswered ❔ Need help making JS work with a Kinect

1 Upvotes

Hello everyone, I’m Victor. I’m not a coder in any way shape or form, so please be kind. I’m working with this Pen I found online for a graduation project and I’m trying to make it work with a Kinect. The goal is to turn the interaction that happens when the mouse hovers the dotted area reactive to people’s presences. This is the code I’m working on: https://codepen.io/victorvercillas/pen/oNYPodV

I know it’s possible I just have no idea where(or how) to start.

Important info: The Kinect I got available is 1st gen.

let x = 0, 
    y = 0, 
    strength = 200;

let mouseMoveHandler = function (e) {
    x = e.pageX;
    y = e.pageY;
};

var points = Array.from(document.querySelectorAll("circle"), (el) => {
    return {
      circle: el,
      x: Number(el.getAttribute("cx")),
      y: Number(el.getAttribute("cy")),
      ox: Number(el.getAttribute("cx")),
      oy: Number(el.getAttribute("cy"))
    };
});

function newElementPosCalc(element, x, y) {
  let dx = element.x - x;
  let dy = element.y - y;
  let angle = Math.atan2(dy, dx);
  let dist = strength / Math.sqrt(dx * dx + dy * dy);
  element.x += Math.cos(angle) * dist;
  element.y += Math.sin(angle) * dist;
  element.x += (element.ox - element.x) * 0.1;
  element.y += (element.oy - element.y) * 0.1;
  return element;
}

function animate() {
  points.forEach((el, i) => {
    // start repulsion calculation
    var newEl = newElementPosCalc(el, x, y);
    // end repulsion calculation
    el.circle.setAttribute("cx", newEl.x);
    el.circle.setAttribute("cy", newEl.y);
  });
  window.requestAnimationFrame(animate);
};

window.addEventListener("mousemove", mouseMoveHandler);
animate();

Some backstory:

The dots you see on the black square will be project on the ground from a projector pointing down. I’d like to make them reactive to whoever walks over them, with that repulsive effect you see on the code when you hover the mouse over the dots.

Thank you so much for anyone taking their time to try to help me in any way, just by reading this. Hope you’re having a good week!


r/JavaScriptHelp • • Feb 27 '21

💡 Advice 💡 What’s the best standalone client side router?

Thumbnail self.frontend
1 Upvotes

r/JavaScriptHelp • • Mar 08 '21

❔ Unanswered ❔ Unity Content Error, Cannot read property ‘1’ of null message.

1 Upvotes

Hello, I have a MacBook and I try to play this game called justfall.lol and I get the cannot read property ‘1’ of null message, how do I fix this? I am a complete beginner so I might need a step by step.


r/JavaScriptHelp • • Mar 13 '21

✔️ answered ✔️ Need help storing parent classes into array (possibly with recursion)

2 Upvotes

I'm trying to take html that looks like this:

    <div data-condition=" noise = 'purr' "> 
       <div class="include" data-include="cat"></div> 
    </div>
    
    <div data-condition=" noise = 'bark' "> 
       <div  data-condition=" tail = 'wag' ">
           <div class="include" data-include="dog"></div> 
       </div>
    </div>

and convert it to an object that looks like this

data = {   
    cat: { noise: 'purr' },
    dog: {  noise: 'bark',  tail: 'wag'  }
}

I have a file with over a hundred of these blocks, and need to log (into the object) what generates each data-include. hoping someone can help. I'm using jquery but vanilla Js works as well. thanks!


r/JavaScriptHelp • • Mar 14 '21

❔ Unanswered ❔ Canvas and mouse position difference

1 Upvotes

So I have this little project and code,

https://jsfiddle.net/Urrby/bhdx6o3L/

The problem is I can't get the line to match the tip of the mouse, there is always space between the cursor and the line drawn. I know this has been asked 100 times, but I don't understand how to resize the canvas and window and mouse position to match. I'm not looking for just a solution, It would be nice if someone can dumb it down and explain why this doesn't work, and what is it that I have to fix. I'm really lost.

Thank you in advance for your help.


r/JavaScriptHelp • • Mar 02 '21

❔ Unanswered ❔ Detect if there is a new item in the news (google search)

1 Upvotes

Hi,

So I'm planning to build a bot, that will automatically search in the google news for a certain topic everyday. And if there is a new item in the news, The bot will automatically send a message to the user.
Is it possible to detect if there is a new item on the news? If yes, can you give me some advice how to do it, I will truly appreciate your help, thank you.