View Full Version : Form Calculations/Validations

12-07-2004, 03:42 AM
I'm fairly new to javascripting. I want to have a form on my website that will do the following.

When a person types in a shell size the script will calculate the height and size of a fireworks shell burst.

Math calculations are as followed.

Height = Shell size times 100

burst size=shell size times 75

I also want validate the form.

I'm not sure where to start. Any help would be great

12-07-2004, 05:28 AM
you can use this to point you in the right direction:

<script language="javascript">
function calcForm()
var shellSize = document.myForm.sSize.value;

if(isNaN(shellSize) || shellSize == "")
alert("Please enter a valid value");
return false;
document.myForm.Height.value = parseFloat(shellSize) * 100;
document.myForm.Size.value = parseFloat(shellSize) * 75;
return true;

<form name="myForm" action="">
Shell Size:<br>
<input type="text" name="sSize">
<input type="button" name="calc" value="Calculate" onclick="return calcForm();"><br>
<input type="text" name="Height" readonly="readonly"><br>
<input type="text" name="Size" readonly="readonly"><br>