The first version is written entirely in JavaScript.
It doesn't check for the validity of the values before calculating the cost
and displaying it.
One drawback is that if we change the choices or costs, we have to make
big changes to the page.
Version 1
The second version uses the web page to gather the information
but all the checking and calculation is done in a Perl CGI program.
This means the page doesn't change, but it also means that the
user has to wait to see any errors.
Version 2
Version 2 CGI program
The third version uses the web page to gather the information
and do all the checking.
The user gets quick error feedback.
And the CGI program is smaller and thus a little faster.
But making changes, especially adding new products, is difficult.
Version 3
Version 3 CGI program
The fourth version uses the web page to gather the information
and do all the checking like the third version.
The CGI program reads the cost data from a file.
Changing the file will change the cost of buying a beverage.
Version 4
Version 4 CGI program
Version 4 data file
The fifth version uses the web page to gather the information
and do all the checking like the third version.
The CGI program reads the cost data from a database.
Changing the database will change the cost of buying a beverage.
Version 5
Version 5 CGI program
Version 5 database creation commands
Version 5 database load commands
The sixth version uses the web page to gather the information
and do all the checking like the third version.
The CGI program, now written in PHP, reads the cost data from a database.
The database is the same as the one in version 5.
Changing the database will change the cost of buying a beverage.
Version 6
Version 6 PHP program
The seventh version creates the web page from a PHP program.
There is no HTML file.
It makes use of extra data in the database to create the brand
and size lists on the fly.
So to add ne beverages or sizes, we only have to change the
database, not the web site code.
The web page generated by the PHP program uses the PHP program
from version 6 to do the form checking.
The database is the same as the one in version 5.
Changing the database will change the cost of buying a beverage.
Version 7
Version 7 JavaScript code
Here is a zip file containing all the examples.