Title: Dropdown Calculator
Last modified: April 22, 2023

---

# Dropdown Calculator

 *  Resolved [klingbeil](https://wordpress.org/support/users/klingbeil/)
 * (@klingbeil)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/)
 * Hello;
   How to make a simple calculation example with dropdown menu.
 * For example, how do we do this?
 * Dropdown menu
 * If Value “A” is selected;
   The fieldname at the bottom is B number / 100 * C Number
 * 
   If Value “B” is selected;Number B x Number C / 100
 * Could you please give an example of this?
   Thanks
    -  This topic was modified 3 years, 1 month ago by [klingbeil](https://wordpress.org/support/users/klingbeil/).

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/dropdown-calculator/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/dropdown-calculator/page/2/?output_format=md)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16677700)
 * Hello [@klingbeil](https://wordpress.org/support/users/klingbeil/)
 * Thank you very much for using our plugin. I’ll try to describe the process with
   a hypothetical example.
 * Assuming you have the dropdown field fieldname1 with two choices, “A” and “B”,
   and the number fields fieldname2 and fieldname3. If the user selects the “A” 
   choice in fieldname1, you want to calculate fieldname2/(100_fieldname3). And 
   if the user selects the “B” choice, calculate (fieldname1_fieldname2)/100.
 * In this hypothetical case, you can insert a calculated field in the form and 
   enter the equation:
 *     ```wp-block-code
       IF(fieldname1 == 'A', fieldname2/(100*fieldname3), (fieldname1*fieldname2)/100)
       ```
   
 * Best regards.
 *  Thread Starter [klingbeil](https://wordpress.org/support/users/klingbeil/)
 * (@klingbeil)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16677716)
 *     ```wp-block-code
       (function(){
           var yuzdeA = 0;
           if (fieldname14 == 'A') {
               yuzdeA = (fieldname16*fieldname17)/100;
           }
           jQuery('#calculation-yuzdeA').html(yuzdeA);
           return yuzdeA;
       })();
       ```
   
 * How to use PREC correctly in this section?
    -  This reply was modified 3 years, 1 month ago by [klingbeil](https://wordpress.org/support/users/klingbeil/).
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16677767)
 * Hello [@klingbeil](https://wordpress.org/support/users/klingbeil/)
 * You can edit the equation as follows:
 *     ```wp-block-code
       (function(){
           var yuzdeA = 0;
           if (fieldname14 == 'A') {
               yuzdeA = PREC(fieldname16*fieldname17/100, 2);
           }
           jQuery('#calculation-yuzdeA').html(yuzdeA);
           return yuzdeA;
       })();
       ```
   
 * Best regards.
 *  Thread Starter [klingbeil](https://wordpress.org/support/users/klingbeil/)
 * (@klingbeil)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16678041)
 * I am so grateful to you for this awesome plugin it solves many of our tasks.
 *     ```wp-block-code
       (function(){
       var result = fieldname1+fieldname2;
       jQuery('#result-container').html(result);
       return result;
       })()
       ```
   
 * Can we add two letters “XX” to the end or beginning of the output value? I want
   to write the unit of the result..
   Thank you very much.And do we have a chance
   to print the result as digits?Example: As 2,568,22.
    -  This reply was modified 3 years, 1 month ago by [klingbeil](https://wordpress.org/support/users/klingbeil/).
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16678147)
 * Hello [@klingbeil](https://wordpress.org/support/users/klingbeil/)
 * The suffix symbols can be entered through the “Symbol to display at the end of
   the calculated field” attribute in the calculated field settings. However, if
   you want to display the symbols in the #result-container tag, you should include
   the symbols as part of the equation:
 *     ```wp-block-code
       (function(){
       var result = fieldname1+fieldname2;
       jQuery('#result-container').html(result+'XX');
       return result;
       })()
       ```
   
 * Note that if the tag with the result-container id is inside the form’s structure,
   you don’t need to make the assignment from the equation.
 * For example, if the calculated field is the fieldname123, you can insert a tag
   as part of the “HTML Content” field as follows:
 *     ```wp-block-code
       <span data-calculated-field="fieldname123"></span>
       ```
   
 * and edit the equation:
 *     ```wp-block-code
       PREC(fieldname1+fieldname2,2);
       ```
   
 * The plugin would do the assignment by itself, including the symbols entered through
   the “Symbol to display at the end of the calculated field” attribute in the calculated
   field settings.
 * Best regards.
 *  Thread Starter [klingbeil](https://wordpress.org/support/users/klingbeil/)
 * (@klingbeil)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16680696)
 * Hello, with this code, many of my calculation problems have been solved.
 *     ```wp-block-code
       (function(){
       var result = fieldname1+fieldname2;
       jQuery('#result-container').html(result+'XX');
       return result;
       })()
       ```
   
 * We are working with this code while printing the result on the screen.
 *     ```wp-block-code
       Conclusion : <span data-calculated-field="fieldname123"></span>
       ```
   
 * The question I want to ask is as follows.
 * Dropdown “A” when we choose.
 * **Conclusion : brings the result.**
 * Now to my question;
 * Dropdown “B” when we choose. (So another option)
 *     ```wp-block-code
       Conclusion : <span data-calculated-field="fieldname123"></span>
       ```
   
 * How can I change the text of Conclusion : here?
   For example, when I choose the
   A criterion, it will write **CONCLUSİON1**. When I choose the B criterion, it
   will write **CONCLUSİON2**.
 * **There is no problem printing the result value.**
 *  But I want to make the text “**CONCLUSİON1**, **CONCLUSİON2**” change according
   to the criteria.
 * Example : [Calcu](https://www.kolayhesapla.net/matematik/indirim-hesaplama/)
 * Thanks.
    -  This reply was modified 3 years, 1 month ago by [klingbeil](https://wordpress.org/support/users/klingbeil/).
    -  This reply was modified 3 years, 1 month ago by [klingbeil](https://wordpress.org/support/users/klingbeil/).
    -  This reply was modified 3 years, 1 month ago by [klingbeil](https://wordpress.org/support/users/klingbeil/).
    -  This reply was modified 3 years, 1 month ago by [klingbeil](https://wordpress.org/support/users/klingbeil/).
    -  This reply was modified 3 years, 1 month ago by [klingbeil](https://wordpress.org/support/users/klingbeil/).
    -  This reply was modified 3 years, 1 month ago by [klingbeil](https://wordpress.org/support/users/klingbeil/).
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16681075)
 * Hello [@klingbeil](https://wordpress.org/support/users/klingbeil/)
 * You are trying to modify your plain texts, not the equations’ results. So, you
   have multiple alternatives:
 * * You can insert two fields with their corresponding texts and configure them
   as dependent on the dropdown choices.
 * Ex. the HTML Content field fieldname333 with content**:**
 *     ```wp-block-code
       Conclusion : <span data-calculated-field="fieldname123"></span>
       ```
   
 * And the HTML Content field fieldname444 with content:
 *     ```wp-block-code
       Conclusion2 : <span data-calculated-field="fieldname123"></span>
       ```
   
 * Finally, configure the fieldname333 and fieldname444 as dependent on the choices
   in the dropdown field.
 * Learn more about dependencies by reading the following blog post:
 * [https://cff.dwbooster.com/blog/2020/03/01/dependencies](https://cff.dwbooster.com/blog/2020/03/01/dependencies)
 * * You can modify the text from the equation’s code. Enclose the text into a tag
   as follows:
 *     ```wp-block-code
       <span class="my-text">Conclusion</span> : <span data-calculated-field="fieldname123"></span>
       ```
   
 * And then, assuming the dropdown field is the fieldname555, edit the equation 
   as follows:
 *     ```wp-block-code
       (function(){
       if(fieldname555 == 'A') jQuery('.my-text').html('Conclusion');
       else jQuery('.my-text').html('Conclusion 2');
   
       return fieldname1+fieldname2;
       })()
       ```
   
 * Or, you can insert another calculated field as an auxiliary (you can hide it 
   by ticking a checkbox in its settings). I’ll call it fieldname666. Enter the 
   equation:
 *     ```wp-block-code
       IF(fieldname555 == 'A', 'Conclusion', 'Conclusion 2')
       ```
   
 * And edit the summary text as follows:
 *     ```wp-block-code
       <span data-calculated-field="fieldname666"></span> : <span data-calculated-field="fieldname123"></span>
       ```
   
 * Best regards.
 *  Thread Starter [klingbeil](https://wordpress.org/support/users/klingbeil/)
 * (@klingbeil)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16681165)
 * Thanks a lot
   My last question..
 *     ```wp-block-code
       (function(){
       var kdvoran= PREC(fieldname16-fieldname4,  2, true);
       jQuery('#calculation-kdvoran').html(kdvoran+' TL');
       return kdvoran;
       })()
       ```
   
 * In the code, a top option is in the dropdown menu (if the fieldname14 criterion
   is value B;
 *     ```wp-block-code
       (function(){
       var kdvoran= PREC(fieldname16+fieldname4,  2, true);
       jQuery('#calculation-kdvoran').html(kdvoran+' TL');
       return kdvoran;
       })()
       ```
   
 * I want it to sum up taking into account the criteria.
 * **I did this but it didn’t work.**
 *     ```wp-block-code
       (function() {
         var fieldname14_value = jQuery('#fieldname14').val();
         var fieldname16_value = parseFloat(jQuery('#fieldname16').val());
         var fieldname4_value = parseFloat(jQuery('#fieldname4').val());
         var kdvoran;
   
         if (fieldname14_value === 'kriter B') {
           kdvoran = PREC(fieldname16_value - fieldname4_value, 2, true);
         } else {
           kdvoran = PREC(fieldname16_value + fieldname4_value, 2, true);
         }
   
         jQuery('#calculation-kdvoran').html(kdvoran + ' TL');
         return kdvoran;
       })();
       ```
   
 *  Thread Starter [klingbeil](https://wordpress.org/support/users/klingbeil/)
 * (@klingbeil)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16681229)
 *     ```wp-block-code
       (function(){
       var kdvoran; 
   
         if (fieldname14 == 'B') {
           kdvoran = PREC(fieldname16 + fieldname4, 2, true);
         } else {
           kdvoran = PREC(fieldname16 - fieldname4, 2, true);
         }
   
       jQuery('#calculation-kdvoran').html(kdvoran+' TL');
       return kdvoran;
       })()
       ```
   
 * finally solved, thanks.
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16681237)
 * Excellent !!!!
 *  Thread Starter [klingbeil](https://wordpress.org/support/users/klingbeil/)
 * (@klingbeil)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16707281)
 * Hello; I am improving myself a lot because of you. We were having trouble changing
   the last text field. But today I solved it.
   Namely;I wrote the code as follows,
   my-text field is changing without any problem..
 *     ```wp-block-code
       (function(){
         var dikalanhesaplama = 0;
         var karealanhesaplama = 0;
           if (fieldname14 == 'A') {
           dikalanhesaplama = PREC(fieldname1 * fieldname2, 2, true);
           jQuery('#calculation-dikalanhesaplama').html(dikalanhesaplama + ' cm2');
       	jQuery('.my-text').html('Dikdörtgen Alanı :');
         }
         if (fieldname14 == 'B') {
           kareaanhesaplama = PREC(fieldname1 * fieldname2, 2, true);
           jQuery('#calculation-kareaanhesaplama').html(kareaanhesaplama + ' cm2');
       	jQuery('.my-text').html('Kare Alanı :');
         }
         return [dikalanhesaplama,kareaanhesaplama];
       })();
       ```
   
 * This is how I did it while writing the result.
 *     ```wp-block-code
       <b class="my-text mobile-aciklama">Hesaplama Sonucu :</b></td><td style="text-align: right;"><b><span data-calculated-field="fieldname14" class="mobile-sonuc" style="color:#ff6504;"></span></b>
       ```
   
 * Description variables work fine. But I couldn’t print the results, where am I
   going wrong?
   Thanks a lot.
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16707373)
 * Hello [@klingbeil](https://wordpress.org/support/users/klingbeil/)
 * Please, edit the tag as follows:
 *     ```wp-block-code
       <b class="my-text mobile-aciklama">Hesaplama Sonucu :</b></td><td style="text-align: right;"><b><span data-cff-field="fieldname14" class="mobile-sonuc" style="color:#ff6504;"></span></b>
       ```
   
 * Replaces `data-calculated-field` with `data-cff-field`
 * Best regards.
 *  Thread Starter [klingbeil](https://wordpress.org/support/users/klingbeil/)
 * (@klingbeil)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16707439)
 * Hello, it didn’t.
   In fact, in the return field;
 *     ```wp-block-code
         return [dikalanhesaplama,kareaanhesaplama];
       ```
   
 * It works when I define someone. But when I select criteria fieldname14 it doesn’t
   work.
   Could it be an error in the computational coding?Thanks
 * Additional Note: [Video Link](https://s12.gifyu.com/images/e015a7d3-6354-4baa-b259-88e187e3b2cb.gif)
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16707466)
 * Hello [@klingbeil](https://wordpress.org/support/users/klingbeil/)
 * The data-cff-field=”fieldname14″ attribute works if it is in the form’s structure.
   If the tag is outside the form, you should assign the information by code.
 *     ```wp-block-code
       (function(){
         var dikalanhesaplama = 0;
         var karealanhesaplama = 0;
           if (fieldname14 == 'A') {
           dikalanhesaplama = PREC(fieldname1 * fieldname2, 2, true);
           jQuery('#calculation-dikalanhesaplama').html(dikalanhesaplama + ' cm2');
       	jQuery('.my-text').html('Dikdörtgen Alanı :');
         }
         if (fieldname14 == 'B') {
           kareaanhesaplama = PREC(fieldname1 * fieldname2, 2, true);
           jQuery('#calculation-kareaanhesaplama').html(kareaanhesaplama + ' cm2');
       	jQuery('.my-text').html('Kare Alanı :');
         }
         jQuery('.mobile-sonuc').html(CONCATENATE(dikalanhesaplama, ',', kareaanhesaplama));
         return [dikalanhesaplama,kareaanhesaplama];
       })();
       ```
   
 * Best regards.
 *  Thread Starter [klingbeil](https://wordpress.org/support/users/klingbeil/)
 * (@klingbeil)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/#post-16707540)
 * You’re a little confused, let me clear it up.
 * The code at the bottom multiplies 2 fields and writes the result.
 *     ```wp-block-code
       dikalanhesaplama = PREC(fieldname1 * fieldname2, 2, true);
       ```
   
 *     ```wp-block-code
       karealanhesaplama = PREC(fieldname1 * fieldname2, 2, true);
       ```
   
 * I get these results if the fieldname criterion is A
 *     ```wp-block-code
       (function(){
         var dikalanhesaplama = 0;
         var karealanhesaplama = 0;
           if (fieldname14 == 'A') {
           dikalanhesaplama = PREC(fieldname1 * fieldname2, 2, true);
           jQuery('#calculation-dikalanhesaplama').html(dikalanhesaplama + ' cm2');
       	jQuery('.my-text').html('Dikdörtgen Alanı :');
         }
         if (fieldname14 == 'B') {
           kareaanhesaplama = PREC(fieldname1 * fieldname2, 2, true);
           jQuery('#calculation-kareaanhesaplama').html(kareaanhesaplama + ' cm2');
       	jQuery('.my-text').html('Kare Alanı :');
         }
         jQuery('.mobile-sonuc').html(CONCATENATE(dikalanhesaplama, ',', kareaanhesaplama));
         return [dikalanhesaplama,kareaanhesaplama];
       })();
       ```
   
 *     ```wp-block-code
       jQuery('.my-text').html('Dikdörtgen Alanı :');
       ```
   
 * **Dikdörtgen Alanı :** I am trying to print results. If the criterion is B, the
   explanation part changes and I try to print it by calculating according to the
   B criterion.
 * The last piece of code you sent is merging.
   For example, fieldname1(25 values)*
   fieldname2 (25 values) If the criterion is A: 625 is required;Merging is doing;
   It prints a result of 625,625.
 * In summary, what we want is if the criterion A is selected, write the result:
   625.
   If B Criterion is selected: Write the calculation result in B criterion.
   Thanks

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/dropdown-calculator/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/dropdown-calculator/page/2/?output_format=md)

The topic ‘Dropdown Calculator’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 18 replies
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/dropdown-calculator/page/2/#post-16707816)
 * Status: resolved