Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Calculations/Validations

    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

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    you can use this to point you in the right direction:
    Code:
    <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>
    Last edited by Brandoe85; 12-07-2004 at 05:30 AM. Reason: I know....i can't spell....


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •