conditional form options?
I hope this title makes some sense!
What I'm trying to do is to create a fee calculator. The calculator would add fees for residence and meal plan and come up with a total. The fee for residence is dependent on the academic term, residence facility and room type. Only certain room types are available in each residence. Meal plan options are also dependent on the residence facility (i.e. only certain options are available for each residence).
What I want is for the form to only display the available options depending on what the user chose in the last option. This is the same as what happens on forms sometimes if, say, you choose your country and it automatically chages the state/province list to match.
The form would look something like this:
Term: (fall/winter/spring)
Residence facility: (changes based on term)
Room Type: (changes based on the residence facility selection)
Meal Plan: (changes based on the residence facility selection)
Total: (calculated based on above options)
How do I do this??? I have no idea what's required - can I do this with javascript? Do I need some server side processing??? I could send this downstairs to our web apps guy to do but I'd like to at least try it myself.
Busy posted this at 21:10 — 13th October 2006.
He has: 6,151 posts
Joined: May 2001
Is it to be done on one page or several?
Javascript is the only way if on one page (with use of css of hiding the other stuff etc) but if you want several pages then just server side or static html would do.
Have a look for javascript quiz code if you want some base code to work from, something from this lot may be of some help
http://javascriptkit.com/script/script2/picklist.shtml
http://javascriptkit.com/script/script2/picklist2.shtml
http://javascriptkit.com/script/script2/comboquiz.shtml
http://javascriptkit.com/script/cut180.shtml
http://javascriptkit.com/script/cut142.shtml
Megan posted this at 13:27 — 16th October 2006.
She has: 11,421 posts
Joined: Jun 1999
Thanks, Busy. It will be on just one page I think. I think the calculations would be easy. Switching the values for each form depending on another value is what I'm really not sure about.
But then, I haven't coded javascript myself in years so this could be an adventure!
Megan
Connect with us on Facebook!
Abhishek Reddy posted this at 15:19 — 16th October 2006.
He has: 3,348 posts
Joined: Jul 2001
It's an interesting problem, and definitely do-able on one page with Javascript alone.
A rough sketch of one possible approach for the script:
For steps 1-3, you could use prototypes to define terms etc and their properties. To filter and populate the selection boxes, you'd loop over the arrays, and use the DOM Node methods to add elements.
I guess that'll be the basic functionality. From there, it would be easy to make it possible, say, to:
Should be fun! Remember to build it incrementally and keep it simple. Good luck.
Megan posted this at 15:36 — 16th October 2006.
She has: 11,421 posts
Joined: Jun 1999
Yikes, that sounds scary! I'm fiddling around with this and doing what I can - I have no idea how to do a lot of what you mentioned there! Will have to work on my javascript a lot! I found a lot of premade scripts and tutorials and stuff so I'll work from there...
Megan
Connect with us on Facebook!
Abhishek Reddy posted this at 15:45 — 16th October 2006.
He has: 3,348 posts
Joined: Jul 2001
Don't worry, it only seems scary because I've run through it very quickly from top to bottom. I'm hoping it'll give you ideas if you should get stuck, rather than prescribing a solution.
Megan posted this at 16:05 — 16th October 2006.
She has: 11,421 posts
Joined: Jun 1999
Okay, well, I'm sorting through some of the other options but I might try what you've got there and see how far I get
Megan posted this at 20:41 — 30th April 2007.
She has: 11,421 posts
Joined: Jun 1999
I'm back at this again! I had put it on the back burner for awhile but my boss mentioned that it would be good to have for our next marketing push.
Now I'm thinking about using some combination of PHP & javascript. Now I have all the possible values stored in three database tables (residences - for the residence names & types, meal plans - for the meal plan types & costs, and details.Oops, forgot something for the terms available ... hmmm...)
Anyway, does anyone have any suggestions for how I could pull the values from the database and then change the available items when something from one field is selected?
Here is my current prototype page (a bit of a mess right now):
http://www.housing.uwaterloo.ca/_testbed/calculator/calculator.php
Megan
Connect with us on Facebook!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.