...

View Full Version : Form Calculations/Validations



pyrotaz
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

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


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

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


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum