I have written a script that checks a set of radiobuttons to be checked. But due to different possibilities different radiobuttons will show. Is there a way to suppress JavaScript errors when it pops undefined/getElementById is null? Something like the @-char does in PHP? Update: A bit more background info. I’ve made a website where users can submit images and
Tag: javascript
Secure random numbers in javascript?
How do I generate cryptographically secure random numbers in javascript? Answer You can for instance use mouse movement as seed for random numbers, read out time and mouse position whenever the onmousemove event happens, feed that data to a whitening function and you will have some first class random at hand. Though do make sure that user has moved the
How to find the key code for a specific key
What’s the easiest way to find the keycode for a specific key press? Are there any good online tools that just capture any key event and show the code? I want to try and find the key codes for special keys on a mobile device with a web browser, so an online tool would be great. Answer Here’s your online
Synchronizing loading js files with ajax calls and loading js files with tag
core.js: me.js CASE 1: CASE 2: The problem is that for case 1 I get an alert, as I should , but for case 2, no alert… So the question is: there is a load event for the <script> tag? Qhat can I use to synchronize the files to work on case 2 (while debugging in IE8, I noticed that
Why is JavaScript sending an element to my event handler, when that element has no event?
This html: This JavaScript takes the span containing the image and text, then makes it clickable: If I click on the “Link text,” then the obj in myEvent() is the span. If I click on the image, then the obj is the image element! The image itself has no event. So why isn’t it always the span that gets passed
Finding the max value of an attribute in an array of objects
I’m looking for a really quick, clean and efficient way to get the max “y” value in the following JSON slice: Is a for-loop the only way to go about it? I’m keen on somehow using Math.max. Answer To find the maximum y value of the objects in array: or in more modern JavaScript:
Checking if an email is valid in Google Apps Script
I’m using the built-in api for scripting against Google Spreadsheets to send some booking confirmations, and currently my script breaks if someone has filled in an invalid email. I’d like it to just save some data to a list of guests that haven’t been notified, and then proceed with looping through the bookings. This is my current code (simplified): According
Keep the selection in a textarea
Can I prevent the loss of selection in the “onblur” event? Answer I don’t think that’s a good idea. A user with mouse in his/her hand can click anywhere on the page. If you get him/her back into the textarea, it won’t be following the principles of web accessibility.
How to declare an array in JS (like I’d do it in PHP)?
Hey, Im trying to make a nested array in JS Chrome’s debugger tells me the ), at the end of the first nested array is an “Unexpected Token” Answer From your code it looks like you’re trying to use PHP-style arrays in JavaScript. JavaScript arrays don’t work like PHP arrays. Here’s something that’s more likely to work: To explain a
Fastest way to duplicate an array in JavaScript – slice vs. ‘for’ loop
In order to duplicate an array in JavaScript: Which of the following is faster to use? Slice method For loop I know both ways do only a shallow copy: if original_array contains references to objects, objects won’t be cloned, but only the references will be copied, and therefore both arrays will have references to the same objects. But this is