Page 1 of 1
Best tool for the job?
Posted: Thu Jan 31, 2008 11:16 pm
by jeffrydell
Sometimes I feel a little like I'm imposing here ... Theory and Design (at least to me) implies a higher level of understanding than my questions, but I can't seem to fit them in other forums.
So - please forgive if I'm a bit elementary here.
As a part of my "project" I need to implement (for lack of a better description) a form which behaves like a spreadsheet.
I've managed to somewhat achieve the desired results with PHP and Javascript - but I'm not 100% satisfied with the performance and I have to seriously doubt that I'm going about this the best way possible.
The form is a Payment Calculator which is customized from client to client. It looks like a standard Invoice with a Quantity on the left, a text description, then the amount for each line calculated on the right.
When the user enters a value on the left, Javascript refreshes the screen and all other dependent values are adjusted before the page gets refreshed. When the user is satisfied that they have completed the form, they click on the Submit button and the form results are POSTed to an array, off we go to the next step.
Any thoughts on what apps / language / etc. I should be looking at to accomplish this in the most effective manner?
Re: Best tool for the job?
Posted: Thu Jan 31, 2008 11:31 pm
by Christopher
Given examples like Google Docs, it could certainly be done in Javascript. And PHP would be a reasonable choice to generate the pages.
Re: Best tool for the job?
Posted: Fri Feb 01, 2008 12:57 am
by Kieran Huggins
I'm tempted to suggest looking at the "observer" pattern in UI programming. Each cell would register with cells it's value is dependent on, so each time an element updates it can forward a "recalc" command to it's observers.
This can certainly be done in JS, and then just be submitted as a form when the user is done.
Re: Best tool for the job?
Posted: Fri Feb 01, 2008 2:44 am
by Maugrim_The_Reaper
Kieran looks on the best path - the one word registering as a red flag from your original post was "refresh". I'm assuming changes don't reload the page here all the time until the final version is submitted?
Re: Best tool for the job?
Posted: Fri Feb 01, 2008 6:49 am
by jeffrydell
Yep - you saw THE red flag! When a value is entered, the page is submitted ... a form action script puts the POST values in an Array then the user is re-routed back to the original script which reloads the page with the array values as defaults and does the calculations to repopulate all values on the screen.
Really inefficient I know, but my skill set could only come up with that solution.
So where can I learn more about the 'observer' pattern?
Re: Best tool for the job?
Posted: Fri Feb 01, 2008 9:01 am
by Maugrim_The_Reaper
Look at jQuery for example. The idea is that a change, sparks a set of calls to all the form elements (cells) which should now update. It's really a simple architecture - do a trial for 10 cells, then scale it up to your needs. The Observer pattern is well known in programming circles - any language description will provide the salient points. Variation on a theme, all cells could notify a standalone object of it's new value, this object would in turn notify other cells (who registered themselves as being interested in the current cell) of the change - triggering them to update.
You'd have to fill in the order of precedence though - subtotal cells would need to update before total cells for example. I did something a while back using a calc-depth priority system - the earlier in the final total calc a sub-total is, the higher it's precedence for receiving notifications.
Re: Best tool for the job?
Posted: Fri Feb 01, 2008 9:29 am
by jeffrydell
Thanks for the lead ... the precedence issue shouldn't be too bad. My issue (in this case) is REALLY WEAK javascript skills. I have other issues, but they're not for discussion here.

Re: Best tool for the job?
Posted: Sat Feb 02, 2008 4:52 am
by Kieran Huggins
jeffrydell wrote:Thanks for the lead ... the precedence issue shouldn't be too bad. My issue (in this case) is REALLY WEAK javascript skills. I have other issues, but they're not for discussion here.

Javascript kicks major ass, jQuery doubly so. I fully encourage you to learn both, they're amazingly useful and will make you a better programmer.
Douglas Crockford's overview is a great place to start (or even restart) your journey:
http://javascript.crockford.com/survey.html
Then give jQuery a look, the DOM is hella annoying without it:
http://jquery.com
Re: Best tool for the job?
Posted: Sat Feb 02, 2008 7:02 am
by jeffrydell
Thanks! Good suggestions now ... learn OOP, Javascript, and jQuery, end world hunger, annnnnd watching the Super Bowl. Hmmm ... just a few things on my To Do list this weekend.
I'll be a super-hero too if I can get all that in!

Re: Best tool for the job?
Posted: Sat Feb 02, 2008 7:16 am
by Kieran Huggins
isn't that what half-time is for?