How Would I: Calculator Page/Form?

Xangis - October 9, 2007 - 16:39

I have an existing Drupal 5 site that I would like to add some financial calculation tools to, things like inflation, etc. So what I'd expect to have is a bunch of different pages (each with its own menu entry in navigation) with things like:

Enter Starting Amount: [textbox]
Enter Inflation Rate: [textbox]
Enter Year: [textbox]
Future Value: [blank textbox]
[Calculate Button]

Ideally the user would enter something like $100 at 3% inflation in 2008 and when the [calculate button] is pressed, the math would be done and the [Future Value] textbox would be filled in with "$97.00". These are just one-time calculations and won't need to be stored anywhere.

How would I do this in Drupal?

The only web programming I've done has been in basic PHP, in which case clicking the "calculate" button would load a new page displaying the value, which I could do easily enough. That's obviously not a smooth way to do things in Drupal because you'd just get a new page displaying the answer(s) without the pretty Drupal framework around it.

Forms API? AJAX? PHP? JavaScript? CCK? Contemplate? Something else entirely?

Please forgive my cluelessness -- although my application programming experience could be measured in decades, my web programming experience is only in months. Just point me in the right direction and I'm sure I can work things out...

Calculators

mlarose - November 17, 2007 - 18:55

I'm looking to do the same thing. I have some online calculators using php here.
--
Mike
http://www.laroseweb.com

=-=

VeryMisunderstood - November 17, 2007 - 19:12

Those calculators are actually using a .js script. Which can be seen by viewing the source.

I believe you can do this using drupal_get_js in a page
_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

looking for similar functionality

vkr11 - October 21, 2008 - 20:18

Any one has any more ideas on this?
- Victor
Better Way to Search Drupal.org | Drupal Jobs | Income Tax India

I can imagine that all

szermierz - February 15, 2009 - 11:15

I can imagine that all manner of methods can be used to deliver a calculator in a module, be that some RIA type thing done with JavaScript, or Flash, even an Applet, or just straight HTML.

Of the straight HTML approach I just gave the use of the Forms API a go and did a small example. A screenshot can be seen here here.

I've been working with Adobe Flex for most of the last couple years and when not Flex then some other technology that reduces the need for page refreshes. So when I started with the Forms API I kept forgetting that I'm dealing with a POST and page refresh and even though I can set results I lose the input values unless I intend to pass them back to the form as well.

Anyway, it's not too hard. Just go through the example of using the Forms API, write your math, then set your results.

This is the programmatic approach. Another approach is to use the WebForm module.

 
 

Drupal is a registered trademark of Dries Buytaert.