Skip to content

Tag: javascript

Convert Python None to JavaScript null

In a Django view I am generating a data set something like this: I am passing this data to a JavaScript variable using: For use in a High Charts script. Unfortunately JavaScript is stumbling when it encounters the None value because actually what I need is null. How can I best replace None with null, and wher…

How do I convert an integer to binary in JavaScript?

I’d like to see integers, positive or negative, in binary. Rather like this question, but for JavaScript. Answer A solution i’d go with that’s fine for 32-bits, is the code the end of this answer, which is from developer.mozilla.org(MDN), but with some lines added for A)formatting and B)checking t…

Connect between different row of table

I have a table with 100 or more rows that are created at runtime in asp.net by Table. This table shows projects of a user. Different user have some different projects. I want when admin clicks on row of name user show rows content list of user project (slideToggle). Answer Take look to this: http://jqueryui.c…

Remove objects on disconnect socket.io

I’m using Nodejs and Socket.io. When the client connects, new JavaScript objects are created. Do these objects just linger forever? Should they be deleted or removed when the client disconnects? Is it even possible to remove an object? I know delete won’t work… Thanks – I guess this is…

What is this JavaScript “require”?

I’m trying to get JavaScript to read/write to a PostgreSQL database. I found this project on GitHub. I was able to get the following sample code to run in Node. Next I tried to make it run on a webpage, but nothing seemed to happen. I checked on the JavaScript console and it just says “require not…

How to fix Error: listen EADDRINUSE while using NodeJS?

If I run a server with the port 80, and I try to use XMLHttpRequest I am getting this error: Error: listen EADDRINUSE Why is it problem for NodeJS, if I want to do a request, while I run a server on the port 80? For the webbrowsers it is not a problem: I can surf on the internet, while

How to reset/uncheck radio button onclick event?

I have 2 radio button with 2 group. The structure is like this Main Radio 1 Main Radio 2 Under Main Radio 2, there’s two more sub radio button. Main Radio 1 Main Radio 2 Sub Radio 1 Sub Radio 2 What am I doing is, in default stage, it will only show Main Radio 1 and Main Radio 2

Shorthand if/else statement Javascript

I’m wondering if there’s a shorter way to write this: I initially tried x = y || 1, but that didn’t work. What’s the correct way to go about this? Answer Note that var x = y || 1; would assign 1 for any case where y is falsy (e.g. false, 0, “”), which may be why it “d…