You are going to write the client-side code for a web-site that
allows a person to vote
for their favorite color. It does three things:
- When the page is loaded, it reads the colorballot.xml file on the
server and updates all the labels for the radio buttons to the
appropriate vote counts.
- Every 10 seconds it reads the color relation on the server
and updates the vote counts.
- Whenever the user presses a radio button, it updates the color relation
on the server and updates the vote count for that color.
The files you need can be found in /home/bvanderz/webhome/cgi-bin/colorBallot_db.
Once you are finished you can either use different browsers or use different tabs to vote in different windows and make sure that each window gets appropriately updated every 10 seconds.
The files perform the following tasks:
- color.html: The main html page that shows the color ballot
- colorballot.sql: Sets up the color relation in the students database
and enters sample data for each tuple.
- countballot.js: Contains event handlers for the onload and radio button
press events and callback functions for handling the response from
the server. The students should complete this file in class.
- getCounts.php: called when the page is loaded and every 10 seconds
thereafter to get the vote counts for the different colors
- ballotcount.php: called in response to the onload event. It updates
the vote count for the selected color and returns the new vote count.
If other people have voted in the last 10 seconds,
then the vote count might increase by more than 1.
Steps For You To Complete
You should complete these steps in the following order:
- Load colorballot.sql in the mysql interpreter to create
the Colors relation in your database.
- Add your username, sql password, and sql database name to the
getCounts.php and ballotcount.php files. If you want to see what
their json output looks like, then you can run them as follows:
php-cgi getCounts.php
php-cgi ballotcount.php color='red'
You can of course use any of the 5 colors that are inserted into the
Colors relation.
- Complete countballot.js.