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 to the CF scene
    Join Date
    Jul 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    calculate within form AND send the input

    I use a form in which I i have 3 inputfields. The third field is filled in by pressing a button which calculates the value, based on the input of value 1 and 2.

    - input 1 <input ...>
    - input 2
    - input 3 for ex. = value input 1 / input 2 + 150
    press button to calculate
    - sent

    However, when i make the calculation, nothing is sent anymore. Whet can i do to keep the values as input, but still make a
    calculation. I want to send all 3 the values.

    Thanx!

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe this?
    Code:
    <script>
    function calcAndSend(f) {
    	var v1 = parseInt(f.elements['val1'].value);
    	var v2 = parseInt(f.elements['val2'].value);
    	var answer = v1/v2 +150;
    	f.elements['solution'].value = answer;
    	return true;
    	}
    </script>
    
    (...HTML...)
    
    <form onSubmit="return calcAndSend(this)">
    Value 1<input type="text" id="val1" name="val1" /><br/>
    Value 2<input type="text" id="val1" name="val1" /><br/>
    <input type="hidden" name="solution" id="solution" />
    <input type="submit" value="Send Data" />
    </form>
    
    (...HTML...)


  •  

    Posting Permissions

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