ECMAScript (commonly referred to as JavaScript) is primarily used for scripting web-pages but also has several embedded forms and stand-alone interpreters / JIT engines. Use this tag for questions regarding ECMAScript 5 and its dialects / implementations: JavaScript, JScript, etc., excluding ...

learn more… | top users | synonyms

5
votes
2answers
30 views

Varying a second drop-down's options based on a first selection

I have some javascript code that allows users to select a plan which triggers the second select box to populate with options. The code works, however, it seems to be very inefficient. Any advice on ...
3
votes
0answers
35 views

Tooltip plugin for portfolio website

I am writing my own tooltip plugin for my portfolio website that I am currently working on. So far I have this code below. It works rather well however I feel that there is a lot I could improve. ...
0
votes
0answers
19 views

Codility training: Find the maximal number of clocks with hands that look identical when rotated [on hold]

Here's the link to the problem: https://codility.com/demo/take-sample-test/clocks The problem is that I can't get 100 points (only 42) out of it. Running time is OK, but for some test cases the code ...
4
votes
2answers
109 views

Retrieve and load playlists from YouTube

I have this code I am using in a private project. The following is a snippet of code I use to retrieve and load playlists from YouTube: for (feedEntry in a.feed.entry) { if ...
1
vote
1answer
32 views

Saving the result of an array.protoype.foreEach() into a variable getting undefined [on hold]

How do I get newData to equal the object array that is produced by the forEach()? It works if I define var result = [] globally and console.log(result); var paragraphs = ["this is a p", "%%this is an ...
4
votes
2answers
27 views

What is the best way to refactor out “temporal dependence” of instance methods?

For example, suppose in a view class we need to instantiate some UI components and then populate the fields. Something like: var View = function() { this._initUI(); this._populateFields(); }; ...
4
votes
2answers
32 views

jQuery wrapper of Parsley.js

In a project, I have a lot of HTML forms without validation and I want to add a front end validation, in a quick way. I start looking for a library and I met Parsley.js. It's a good library, but if I ...
8
votes
2answers
80 views

Can this secure, random generator be improved?

This random generator uses cryptographically secure numbers/chars instead of Math.random(). The Javascript code with jQuery works well but I affect clean code ;) It would be great if you could help me ...
5
votes
1answer
54 views

What are your opinions on these small scripts?

I am new to JavaScript, and I was wondering if anyone can share their opinions on what I have done below: First of all, the following functions are all placed in a file called main.js and that file ...
0
votes
0answers
16 views

Approximating Date for a D3.js timeline + General Style comments

I've updated code from a couple weeks back so I've come back to get more feedback. The original post can be found over here. Here is the updated code: /* * @Author: Gowiem * @Date: 2013-12-17 ...
5
votes
3answers
71 views

Is there anything can be improved in this JavaScript module?

I am using RequireJS JavaScript library. I have the following JavaScript module define for dataservice: define(['jquery'], function ($) { var callApi = function (url, type, dataType, data, ...
5
votes
1answer
133 views

Is there a shorter way to write this jQuery code?

I'm using two category filters from this demo. I give the filters two different sets of classes so they won't affect each other. Since I'm very new to jQuery, all I can come up with is repeating the ...
1
vote
0answers
25 views

Mixing an “app controller” and ng-view [closed]

Is there anything wrong with doing something like this in Angular? <body ng-controller="appCtrl"> <div ng-show="!loggedIn"> <form ng-submit="login()">...</form> ...
5
votes
1answer
58 views

Creating a Deprecated/Obsolete behavior for methods in a JavaScript library

A friend of mine has a popular open source JavaScript library which is quite well used in the community. He is now going through a process of refactoring and applying best practices and conventions ...
4
votes
1answer
32 views

Angular Modular File Structure

My intention is to separate components on a file basis. For example, I want a specific controller to have it's own file (Same goes with services, filters and directives). Of course, files will be ...
4
votes
1answer
19 views

toggleSaveStream button template

I've got a view which has a corresponding template. The template looks something like like: <div id="streamItems" class="left-list droppable-list"></div> <div ...
4
votes
1answer
87 views

Validating HTML Form

I am trying to create a simple validation for forms. I am almost there, but there are few bugs and optimization errors that I am really struggling with. I'm looking for advice on how to make this ...
0
votes
0answers
6 views

Create custom JSON object using jQuery [migrated]

I want to create a custom multilevel JSON object. For that I have written some code, but it's not solving my purpose, although I am still working on it. I need your suggestions to write the code. ...
0
votes
0answers
14 views

Angular Select Population [closed]

This is a xpost from stack exchange. This seems to be a better place for the question. Basically I am trying to add rows to a table via buttons. Once the row is added, if the button is pressed again ...
3
votes
1answer
60 views

Knockout custom binding - have I stored the observable correctly?

I've written a custom binding for Knockoutjs which renders <select> elements with <optgroup> children. When run, this binding adds <optgroup> and <option> DOM elements. In ...
9
votes
3answers
97 views

Displaying random quotes from an array

Is there anything that I could have done better in this code? <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Quotes</title> <style> body { ...
1
vote
1answer
43 views

Which iMacros script is faster?

test1.js var macro; macro ="CODE:"; macro +="URL GOTO=http://tppcrpg.net/map.php?Map=11\n"; macro +="TAG POS=1 TYPE=INPUT:IMAGE FORM=ACTION:/map.php?Map=11 ATTR=NAME:Find"; iimPlay(macro); ...
16
votes
1answer
285 views

Random clothes generator

UPDATED, original code can be found here. Also, my main goal is to not only improve the style of my coding, but also to improve the logic in finding random combinations. As of now it seems way too ...
8
votes
2answers
195 views

Create news ticker animation

I have this function in this fiddle JavaScript: var newsTicker = function (ele) { var eles = ele.find('ul li'), indexEle = 0, dataEle = ele.find('.ticker-post'), ...
8
votes
2answers
66 views

Member list reveals member information on click (#1)

What I'm doing? I'm creating a member-list where initially only the names are visible. Clicking the names reveals the member information. This is done with jQuery by adding/removing classes. I left ...
2
votes
2answers
35 views

Simple registration form with Backbone

I am trying to create simple registration form with Backbone. I need to validate fields on blur, and whole form on submit. HTML: <form> <div><input name="name" type="text" ...
10
votes
3answers
141 views

MS Excel type of grid in jQuery

I have created a MS Excel type of grid in jQuery. I want to learn best practices and I need your comments for more optimized code. Please review the code and offer your suggestions. Demo jQuery: ...
3
votes
1answer
42 views

Checking for a value on selectors

I've got some pretty simple validation that I'm working on, but it seems like I'm repeating myself a bunch of times. There has to be a better way of doing this. I'm simply checking if there is a value ...
3
votes
2answers
112 views

Simplifying this form validation script - version 2

A week ago, I have asked how to simplify a form validation. From the answers, the code now is improved. Can anyone please share their opinion on the approach used below and advise me if there is a ...
6
votes
1answer
232 views

Angular JS Switcharoo multiple select module

I have created a script for going a multiple select option in Angular without using a select box that you have to hold control in order to select multiple items. Demo: ...
10
votes
3answers
141 views

Ultimate Tic-Tac-Toe Challenge

This is my attempt at the Ultimate Tic-Tac-Toe code challenge. It uses jQuery to build out the game grid and find the states of all the "buttons" (actually <div>s) when calculating whether or ...
5
votes
1answer
33 views

Project Euler #41 - pandigital prime

I've written a solution to Euler 41: We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is ...
3
votes
2answers
49 views

Append table cells to select boxes in indexed order

I am having a huge brain fart with efficiency right now. The idea here is if I have a static table (unfortunately formatted this way with the data I've received), how would I appropriately append a ...
2
votes
1answer
49 views

Angularjs Module Registration Structure

I'm using meteor and angular. Since I can't add modules after the angular bootstrap, I made a workaround and somewhat not satisfied with the way it was coded. How can I improve this?: (function() { ...
2
votes
1answer
277 views

Approximating/Sorting groups of dates into buckets + general JS patterns/style

Update: I've updated the code below pretty extensively and posted a new question over here. I'm working on a directed study project with a professor of mine helping him build out a Django based ...
8
votes
2answers
138 views

Rotating array members

I had a situation when I needed to move all array elements in circular fashion. When I say this, I mean: 0 1 2 3 1 2 3 0 2 3 0 1 3 0 1 2 So the array: var players = ...
2
votes
1answer
47 views

Dice notation roller in JavaScript

I have the following function, intended to take standard dice notation (XdY+Z) and return a (sort of) random number based on the input. Are there any bugs/bad ideas/optimizable sections I am missing? ...
3
votes
1answer
62 views

Script for generating a report in Google-Spreadsheets. Looks for various values to check and count

It all works exactly as it should. It finds data from today, finds unique emails and puts them in an array. I then check the data again from today, against the emails to total up different values. ...
3
votes
1answer
60 views

Better way to handle a sign up wizard in AngularJS?

I think my current structure is way too repetitive, I feel like I must be missing something that would easily make this sign up wizard work far better. First post on code review, I tried to follow the ...
3
votes
0answers
27 views

knockout binding handler for custom components

I am using a combination of knockoutJS and jQuery. I have a number of jQuery plugins which perform particular re-usable functions, such as a numeric spinbox. I have written a binding handler to ...
6
votes
2answers
82 views

Simplifying this form validation script

Can anyone please help me to simplify this form validation script? It works great but I was just wondering if I can get some help to make it simpler. Your opinion on the approach I used below is ...
21
votes
5answers
1k views

Verifying password strength using JavaScript

I have a function which verifies the Password field and suggests the user to enter a strong password. I also have a label named Password Strength, referring to the strength of a password (very weak, ...
2
votes
2answers
38 views

How to sort two array of objects using Underscore.js?

I am sorting 2 arrays of object like this, but I know this is very bad. Any good approach, like using each method like so? ( I tried, but using each, I am unable to return the object ) var O1 = ...
1
vote
2answers
52 views

Reducing cyclomatic complexity in a simple string concatenation

I have written the following function that takes an address object and builds a string using the object properties. It will later be used to display a tooltip var getAddressTooltip = function ...
1
vote
1answer
76 views

Basic quiz in jQuery

I am using jQuery to implement a basic quiz functionality. How can I improve this code snippet even more? Is there any better way of doing it? I am using jQuery 1.6.4. /*jshint -W065 */ $(function ...
1
vote
1answer
17 views

Is it bad practice to mix in chrome.i18n (internationalization method) into templates?

I'm mixing chrome.i18n into my templates as templateHelpers with Backbone.Marionette. templateHelpers: function () { return { // Mix in chrome to reference internationalize. ...
6
votes
3answers
268 views

Monopoly: Positions

I want to know if this can be trimmed down further. I am repeating myself with this.title and this.position. Also this.position is the corresponding array index, not sure if that is a good idea, if ...
9
votes
2answers
205 views

Matching script tags with regexes

Like anything that shouldn't be done, I decided to see if it is possible to match <script> tags robustly using regexes in PHP. Since there is no arbitrary nesting, I figured it should at least ...
4
votes
1answer
120 views

Check if js variable exists and checking it's value

I feel like this bit of code could be condensed or made better in some way. It may in fact not be but figured I'd get some people smarter then me to have a look. I have multiple pages on my site and ...
7
votes
2answers
110 views

Modular design with Require.js

I am trying to get a better understanding of the modular design pattern and I am using Requirejs to manage my dependencies. I understand separating code into modules (using define with RequireJS) so ...