Watch jQuery Calculation Plug-in in action!

Categories: jQuery

A few weeks ago I posted a blog entry on my jQuery Calculation Plug-in. However, I never think I do an adequate job of describing what it does so I thought a little video might be more useful. Since I just installed Jing a few days ago, I thought this plug-in made a perfect candidate for my first Jing post!

Something I forgot to specifically mention in my demo, but which I think is really significant, is that the dynamic calculation code would work regardless of how many rows were in your table. If you only had 1 item in your basket or 20 items, the exact same code is used. The key is to use a naming convention that is consistent and easy for jQuery to parse.

My original post goes into the technical details behind the demo above, so make sure to read the post for the detailed information on what's going on.

Related Blog Entries

Comments

Jim Priest's Gravatar Very cool! Both the plugin and the interactive demo!! Things like this really shine when you can see them in action!
Kevin Sargent's Gravatar I've just been getting into jquery lately, so it's cool to see more plugins like this get created.

Just remember to never rely on client side code for important values that get sent BACK to the server!
Dan G. Switzer, II's Gravatar @Kevin:

Your absolutely correct in that you should never rely on values, like price, which are passed from the client to the server. This script is to help you implement better UI controls, not to be as an aid for any server-side logic that's needed.

There are many use cases for needing to calculate values based upon your DOM layout and this is the reason I created the plug-in.
Karl Swedberg's Gravatar Excellent demo video, Dan! Great plugin, too. It was really fun to see it in action.
Kevin Sargent's Gravatar @Dan

Exactly, Sorry to make it sound like you wouldn't know better. I guess my comment was for the google searcher / passer byer that was looking for scripts to copy / paste.
Dan G. Switzer, II's Gravatar @Kevin:

It's a point always worth preaching. I've done a lot of presentations at User Groups and Conferences on JavaScript--which tend to focus on the subject of Form Validation (since that's typically one of the first things people want to do with JavaScript.) While I'm a huge advocate of implementing JS-based validation because it improves the UI, I always make sure to re-iterate throughout my presentation that you can not use JS-based validation as your only method of validating data.

Client-side technologies (such as JS) should only be used to enhance the user's experience, but the server-side is where you must validate all input to ensure that the data your receiving is valid.
Njau Ndirangu's Gravatar Nice plugin but has one flaw, it is not versatile enough to be used in multiple tables. There will be a conflict from grandTotal. Another thing, maybe an option were you used checkbox and radio should be implemented. Lets say you click on radio; somehow the price should be included in the calculation. all in all nice plugin.
Dan G. Switzer, II's Gravatar @Njau:

There's no problem using this with multiple tables, you just need to invoke 2 different unique instances. Also, there shouldn't be a problem implementing radio buttons into the equation--provided the elements have valid numeric values.
Morton's Gravatar Dan, would you mind showing with an example how to implement multiple tables and the radio button with values.Would be interesting to know for a rookie like me.

Thanks
Rick's Gravatar I'm also looking for an example of this being used with radio buttons.. Where would I find an example like that or even some documentation that step by steps it??
Daniel's Gravatar Brilliant plugin, Dan! Thank you very much!
Since I am not the superadvanced poweruser... Is there a way to allow only integer numbers or the "." to be ignored?
Dan G. Switzer, II's Gravatar @Daniel:

You could change the regex used to parse the numbers if you wanted just integers to something like:

$.Calculation.setDefaults({
reNumbers: /(\d+(,\d{3})/g
});
Daniel's Gravatar Thank you, Dan! ;)
Phil's Gravatar I'm also trying to get this to work with radio buttons, seems to add all the options up and not only the selected ones.
Dan G. Switzer, II's Gravatar @Phil:

What do your selectors look like? I suspect your selectors are wrong for picking the value from the selected radio element.

Add Comment



If you subscribe, any new posts to this thread will be sent to your email address.