It depends on what exactly has to be done with the form. Javascript may be enough to perform the calculation and return a result.
a cgi file is essentially a file that processes the form and returns formatted results.
In order to use a cgi file your web server must support cgi-script. the cgi file is (normally) stored in a directory called cgi-bin which allows scripts to execute.
In order to determine what 'script u write to do this' you will need to expand on what the function of the form is and the result you wish produced.