ASP Calculator using a form with the GET method

This calculator uses ASP technology. ASP pages contain VBscripts that run on the server, not the client, so the numbers input here cannot be processed by the client computer (which has received no script) - instead the data is posted to another page - actually this same page, which opens a second time. As the second version of the page is prepared by the ASP script the necessary calculations are performed and included in the page that is sent. 

In this particular case it would obviously be more efficient to have a script on the client computer to do the calculations. This page, although demonstrating that an ASP page may be made to appear interactive, above all highlights the limitations of ASP technology. Nevertheless, ASP makes possible many functions that cannot be achieved with client-side scripts as well as offering other advantages such as the invisibility of server-side scripts and the possibility of writing scripts in VBscript knowing there will be no incompatibility with client computers running Netscape Navigator.

/      

The code for this page, including the ASP script, is below. It includes code to check that the contents of each text box can be converted to a number, the actual conversion (without which the 'addition' actually becomes a concatenation like 2+3=23) and a test for division by zero. This page uses the GET method to send the data to another page (which happens to be the same page). The GET method adds the data to the URL of the page requested by the form - you'll see this in the URL bar at the top of the browser window when you hit the Submit button. The POST method can also be used and is demonstrated HERE - it has the advantage that the data does NOT appear in the URL address.

<%
if isnumeric (Request.querystring ("x")) and isnumeric (Request.querystring ("y")) then
	x = cdbl (Request.querystring ("x")) 'convert to number (double precision type)
	y = cdbl (Request.querystring ("y"))
	select case Request.querystring ("operator")
	case "add"
		msg = x & "+" & y & "=" & x+y
	case "subtract"
		msg = x & "-" & y & "=" & x-y
	case "multiply"
		msg = x & "*" & y & "=" & x*y
	case "divide"
		if y = 0 then
			msg = "division by zero!"
		else
			msg = x & "/" & y & "=" & x/y
		end if
	end select
else
	msg = "enter numbers:"
end if
response.write "<b>" & msg & "</b>"
%>
<form method="GET" action="calculator_with_get.asp">
<p>
<input type="text" name="x" size="14">
<input type="radio" name="operator" value="add">+&nbsp; <input type="radio" name="operator" value="subtract">-&nbsp;
<input type="radio" name="operator" value="multiply">*&nbsp;
<input type="radio" name="operator" value="divide">/&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="y" size="20">
<input type="submit" value="Submit" name="process">&nbsp;
</p>
</form>