Skip to content
Advertisement

Tag: javascript

How to Sort a JS Object Literal?

If I have this JS object literal: How can I create a new, sorted object literal: Answer Re: How to sort a JS Object? Answer: You can’t. So instead, you need a more sophisticated data structure. You have many options: You can use a separate array to hold the order of the object’s keys. (This is what @Felix Kling’s answer

JS Busy loading indicator ignore middle click

My busy loading indicator basically works by detecting clicks. However, I just noted that when I middle click an item, it opens a link in a new tab and then the loading indicator shows up forever. How can I tell JS to ignore the middle mouse button? Answer You can try to, but it won’t work very well with all

How to generate short uid like “aX4j9Z” (in JS)

For my web application (in JavaScript) I want to generate short guids (for different objects – that are actually different types – strings and arrays of strings) I want something like “aX4j9Z” for my uids (guids). So these uids should be lightweight enough for web transfer and js string processing and quite unique for not a huge structure (not more

How to know if two arrays have the same values

I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): But it always gives false, even if the two arrays are the same, but with different name. (I checked this in Chrome’s JS Console). So, is there any

Upload file with Ajax XMLHttpRequest

I am trying to send file with XMLHttpRequest with this code. I get this error: T The request was rejected because no multipart boundary was found. What am I doing wrong? Answer There is no such thing as xhr.file = file;; the file object is not supposed to be attached this way. xhr.send(file) doesn’t send the file. You have to

RegEx to match stuff between parentheses

I’m having a tough time getting this to work. I have a string like: And I need regex or a method of getting each match between the parentheses and return an array of matches like: The regex I’m using is /((.+))/ which does seem to match the right thing if there is only one set of parenthesis. How can I

How to simulate a mouse click using JavaScript?

I know about the document.form.button.click() method. However, I’d like to know how to simulate the onclick event. I found this code somewhere here on Stack Overflow, but I don’t know how to use it 🙁 How do I fire a mouse click event using JavaScript? Answer (Modified version to make it work without prototype.js) You can use it like this: Note

Advertisement