1
vote
2answers
63 views

How can I achieve DRY principle in this code?

In the following piece of code I use the same trick three times. But cannot figure out how to write a common function that will do it for all of them. I know there is a toggle method in jQuery that ...
2
votes
2answers
101 views

Whats a better way to do these nested if statements?

I forgot to mention using the result of bar to calculate foo's value in the question I asked here. The function bar only needs to be called if conditionA is true. But when the result of bar ...
3
votes
4answers
323 views

Whats a better (DRY) way to do this if statement

The function bar only needs to be called if conditionA is true. But when the result of bar (conditionB) is false, I want to run the code that would have run if conditionA had been false. Is there a ...
2
votes
1answer
90 views

Cross-language Constants

Background Developing a web application that leverages multiple programming languages. The data flow resembles: Browser » PHP » PL/SQL » XML » XSLT » XHTML + JavaScript » Browser Using different ...
0
votes
1answer
36 views

Simplifying and improving (namely DRY) for flight info fetcher

I've put together this simple fetcher for text data (which I just copy and pasted from a flight info website) - it takes in text data, and spits out an array of objects containing values for each ...
2
votes
2answers
111 views

Can someone help me DRY up these jQuery each loops?

I just posted this on the Stack Exchange, but was told I should post it here: function redundantSee() { var optionSet1 = $('.wrapper:eq(0)'), optionSet2 = $('.wrapper:eq(1)'); ...
2
votes
2answers
74 views

JavaScript optimization

I'm pretty sure there's a way to make this "3 times" duplicated code into only one. Any idea how to do this? if (typeof sync.create!='undefined') { for (var i = 0; i <sync.create.length; i++) ...
1
vote
1answer
79 views

Shortening a webshop page

I am making a simple webshop page where I need to add a couple of products (and their prices). The shop consists of less than 10 products so therefore I decided to build my own solution since it is ...
2
votes
1answer
158 views

Is there a better way to do a Luhn check?

I feel like I should not be duplicating the code to gather the credit card number, but I am not sure how best to do it. Any suggestions? $('input[name="payment\[cc_number\]"]').keyup(function() { ...
2
votes
3answers
1k views

Simple jQuery validation script works but it uses a ton of if/else statements

I've a jQuery validation script to check all form fields for a valid value and prevent form submission and display an error message if any fields fail. It was requested that the validation script not ...
5
votes
3answers
249 views

How can I make this code more DRY?

This code is for a simple language quiz. It fetches two words and related audio files via a JSON call, presents the user with an image that matches one of the words, and challenges the user to make ...
1
vote
1answer
439 views

Javascript get item in object code

So I have some Javascript code that resembles the following: var mylibrary = new (function () { this._getLibraryObj = function () { var newLibraryObj = {}; var libraryData = ...