August 5, 2011

R2D2, you know better than to trust a strange computer!

Posted in Uncategorized at 4:29 pm by dgcombs

My sister sent me some JavaScript a few weeks ago. She was neck deep in some work and needed to know why the columns in the online shopping cart didn’t subtotal and grand total. Oh, Boy! A scavenger hunt!
Cart
As I dug deep into the code I found some odd JQuery calls. “Surely not!” I thought. But yep there it was. Big as life and twice as ugly.
JQuery is the hottest thing in the Web Application/Browser programming world these days. It is a project created by John Resig back in 2006 designed to make JavaScript interactions with the HTML in a web browser simpler and more fluid. Well, in this case, I think they’ve gone too far.
The original cart author had used the JQuery command html() to pull data from the web page. In this case, that was the price of an object. Then it converted the html into a number and added it to a variable succinctly named “number.” Clever! Then it used the same feature to put back result on the web page as html. It was literally using the HTML as the paper tape in an adding machine!
Paper-tape
Just take a peek.

for(i=1; i<=count; i++) {
number += Number($(“#price_txtResult” + i + “-2”).html());
}
$(‘#form_subtotal0’).html(number.toFixed(2));
$(‘#form_producttotal’).html(number.toFixed(2));

Seriously, people don’t really do this, do they? They actually trust the browsing customer to leave the price alone, not modify it on the fly or generate themselves a rebate?

…the mighty Jabba asks why he must pay fifty thousand.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: