I am looking for HTML code that accepts two numbers and do some calculations ie add, subtract, multipy and divide. how do i go about it
Like Doc said you need Javascript here is an example:
[html]
<script language="javascript">
// --------------------------------------------------------------------------------
// Name: btnCalculateTotal_Click
// Abstract: Add 2 Values and update total
// --------------------------------------------------------------------------------
function btnCalculateTotal_Click()
{
var sngValue1 = 0;
var sngValue2 = 0;
var strOperation = "";
var sngTotal = 0;
// Get values from form
sngValue1 = Number(frmSimpleCalculator.txtValue1.value);
sngValue2 = Number(frmSimpleCalculator.txtValue2.value);
strOperation = frmSimpleCalculator.cmbOperation.value;
// Determine what operation to do
switch ( strOperation )
{
case "1": sngTotal = sngValue1 + sngValue2;
break;
}
// Print Value back out to screen
frmSimpleCalculator.txtTotal.value = sngTotal;
}
// --------------------------------------------------------------------------------
// Name: btnClear_Click
// Abstract: clear the screen
// --------------------------------------------------------------------------------
function btnClear_Click()
{
// Set Textboxes to default
frmSimpleCalculator.txtValue1.value = 0;
frmSimpleCalculator.txtValue2.value = 0;
frmSimpleCalculator.txtTotal.value = 0;
// Reset Focus
frmSimpleCalculator.txtValue1.focus( );
}
</script>
<html>
<head>
<title>Calculator</title>
</head>
<body bgcolor="#aaaaaa">
<table style="background-color:black; color:white; width:800">
<tr>
<td>
<strong>Homework 1</strong>
</td>
</tr>
</table>
<form name="frmSimpleCalculator" action="" method="get">
<fieldset name="fraSimpleCalculator" style="width:1">
<legend>Simple Calculator</legend>
<table width="180" border="0">
<!-- Value 1 -->
<tr>
<td align="left">
Value 1:
</td>
<td align="right">
<input type="text" value="0" name="txtValue1" size="10" maxlength="5" style="text-align:right">
</td>
</tr>
<!-- Operation -->
<tr>
<td align="center" colspan="2">
<select name="cmbOperation" size="1">
<option value="1" selected>+
<option value="2">-
<option value="3">*
<option value="4">/
</select>
</td>
</tr>
<!-- Value 2 -->
<tr>
<td align="left">
Value 2:
</td>
<td align="right">
<input type="text" value="0" name="txtValue2" size="10" maxlength="5" style="text-align:right">
</td>
</tr>
<!-- Horizontal rule -->
<tr>
<td align="center" colspan="2">
<hr />
</td>
</tr>
<!-- Total -->
<tr>
<td align="left">
Total:
</td>
<td align="right">
<input type="text" value="0" name="txtTotal" size="10" maxlength="5" style="text-align:right">
</td>
</tr>
<!-- Calculate Button -->
<tr>
<td align="center" colspan="2">
<input type="button" value="Calculate Total" name="btnCalculateTotal" style="width:150" OnClick="btnCalculateTotal_Click();">
</td>
</tr>
<!-- Clear Button -->
<tr>
<td align="center" colspan="2">
<input type="button" value="Clear" name="btnClear" style="width:150" OnClick="btnClear_Click();">
</td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
[/html]
I removed part of the code so you can try for yourself.