What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    Values are not clearing from calculation when user deselects option or changes option

    Asked by tuyeni on May 01, 2014 at 09:19 AM

    In the form if the user makes a selection, the value is added to the calculation. The selection can be from the radio box or checkmark etc. Just say the radio box seletcion values are 15 and 20. If the user makes the appropriate selection for 20 then that field is brought into the calculation. If the user changes their mind and goes and deselect 20 and to select 15 or any other selection with a value, the 20 still remains in the calculation and and the resulting calculation will be 35 instead of 15.

     

    Basically when the user deselects a form field, that value is not being cleared from the calculation.

     

    Thanks again guys!

    Page URL:
    https://secure.myjotform.com/form/41198992776575

    form field Selection select thanks
  • Profile Image

    Answered by jedcadorna on May 01, 2014 at 10:47 AM

    Hello,

    Thank you for contacting us.

    I guess the problem with this is that when you deselect an option that doesn't removed the selected value in the radio or checkbox and the only option in the form builder that will clear the form is using the "Clear form" button which will clear all including texts.

    What I can think of is downloading the form source and adding a clear button beside the "Total" field. If your fine with downloading the form we'll try to make a sample for you.

  • Profile Image

    Answered by tuyeni on May 01, 2014 at 11:13 AM

    Yes. I have to actually host my forms due to some other source code changes so yes I am fine with downloading the source.

  • Profile Image

    Answered by jedcadorna on May 01, 2014 at 12:21 PM
  • Profile Image

    Answered by tuyeni on May 01, 2014 at 02:58 PM

    1. Hi I got tested the form but now the calculation is not happening. 2. Also I guess the user can manually clear the calculation total but can we clear the field value automatically when the actual field is deselected. That would make the form much better from a user standpoint. I havent looked at the code yet but there must be a way to do this

    functionif field1 = deselected

      fieldValue = 0

    return fieldValue to field1

    calculation(field1 + field etc...)

    I hope I'm making sense. Just that if the field one is now deselected, that value AUTOMATICALLY returns back to "0"And thanks for your time.

  • Profile Image
    JotForm Support

    Answered by Mike_T on May 01, 2014 at 04:31 PM

    Please try to add the following 'Insert Text Or Mathematical Calculation into field' condition:

    If 'Please Select Your Option' field 'Is Empty' then output '0' to 'Amount Total'.

    It appears to be working fine when you select/unselect the Tour and Airport Transfer options.

    Example:

    http://form.jotformpro.com/form/41206628126954

    Thank you.

  • Profile Image

    Answered by jedcadorna on May 01, 2014 at 08:23 PM

    Hello,

    I have updated the script and once "Tour" and "Airport Transfer" is deselected the "Amount Total" will be reset to 0.

    Here's the script.

    <script type="text/javascript">
    var input = document.getElementById('input_15'),
    remove = document.getElementById('input_19_0'),
    remove2 = document.getElementById('input_19_1'),
    val = input.value;

    remove.onchange = function() {
    if (this.checked) {
    input.value = "";
    } else {
    input.value = val;
    }
    }
    remove2.onchange = function() {
    if (this.checked) {
    input.value = "";
    } else {
    input.value = val;
    }
    }
    </script>

    You can place this after this line <input type="text" class="form-textbox" data-type="input-textbox" id="input_15" name="q15_amountTotal15" value="0" size="20" /> when you download your form's source code. The form is on this link

    About the calculation it does the calculation and works fine on my end.

  • Profile Image

    Answered by tuyeni on May 04, 2014 at 05:37 PM

    Hi. Yes it does the calculation. Thanks very much. Code is not exactly what I was looking for but it did put me on the right track. Will do my changes and update as to the result.

  • Profile Image
    JotForm Support

    Answered by jonathan on May 04, 2014 at 07:25 PM

    @ tuyeni

    Hi,

    Thank you for updating us. Contact us again anytime if you need our assistance.

  • Profile Image

    Answered by SRWproducts on April 06, 2016 at 05:50 PM

    This worked for us. It is a lot more simple. But we have fields show/hide based on what they selected. Might not work for everyone.

  • Profile Image

    Answered by victor on April 06, 2016 at 06:14 PM

    Thank you for your recommendation SRWProducts. This is also a way to clear values when they are hidden.