Skip to content
Advertisement

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

jQuery check/uncheck radio button onclick

I have this code to check/uncheck a radio button onclick. I know it is not good for the UI, but I need this. $(‘#radioinstant’).click(function() { var checked = $(this).attr(‘checked’, true); …

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

Close/hide an element when clicking outside of it (but not inside)

I have a <div> that exists on a page and I need to make it so that when the user clicks outside of that element it will become hidden, but if the user clicks somewhere within the element, then it should stay. I tried using e.stopPropagation(); and e.preventDefault(); adding it to the click event of that certain DIV but that

Javascript selecbox.options to array?

From what I understand a option elements that popuate select elements in HTML are an array. So basically what i want to do is return an array string that is separated by commas. Tried to do selecbox.options.join(‘,’);, but got an error that its not supported; anyone have an idea why? Answer It is not an array. It is an HTMLCollection.

Advertisement