calculation form: summing two values

  • Profile Image
    pedroof
    Asked on April 15, 2013 at 04:30 PM

    Hello, please I need a css code calculation, the following happens requerir need two numbers and calculate them.

    for example, in a form of expenditure spent on someone fills the hotel and food, and form the sum 2 values .

    thank you

  • Profile Image
    Mike_T
    Answered on April 15, 2013 at 05:22 PM

    We will need to use Javascript for this.

    Here is an example:

    https://shots.jotform.com/mike/examples/summing.html

    I get the form source code, put it to my web page, and added a little summing Javascript function:

    <script language="javascript" type="text/javascript">
    function summing(){
    a=Number(document.form_31046331384952.input_1.value);
    b=Number(document.form_31046331384952.input_3.value);
    c=a+b;
    document.form_31046331384952.input_5.value=c;
    }
    </script>

    These highlighted values are referring to html elements, and will be different on your form.

    Also, I added a call to that function for inputs:

    <input type="text" class=" form-textbox" id="input_1" name="q1_hotelValue" size="20" onchange="javascript:summing();"/>
    </div>
    </li>
    <li class="form-line" id="id_3">
    <label class="form-label-left" id="label_3" for="input_3"> Food value </label>
    <div id="cid_3" class="form-input">
    <input type="text" class=" form-textbox" id="input_3" name="q3_foodValue" size="20" onchange="javascript:summing();"/>

    Please feel free to contact us if you need any more information. We will be happy to help.