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 / 100Could you please give an example of this?
Thanks- This topic was modified 1 year, 7 months ago by klingbeil.
-
Hello @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/(100fieldname3). And if the user selects the “B” choice, calculate (fieldname1fieldname2)/100.
In this hypothetical case, you can insert a calculated field in the form and enter the equation:
IF(fieldname1 == 'A', fieldname2/(100*fieldname3), (fieldname1*fieldname2)/100)
Best regards.
(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 1 year, 7 months ago by klingbeil.
Hello @klingbeil
You can edit the equation as follows:
(function(){ var yuzdeA = 0; if (fieldname14 == 'A') { yuzdeA = PREC(fieldname16*fieldname17/100, 2); } jQuery('#calculation-yuzdeA').html(yuzdeA); return yuzdeA; })();
Best regards.
I am so grateful to you for this awesome plugin it solves many of our tasks.
(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 1 year, 7 months ago by klingbeil.
Hello @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:
(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:
<span data-calculated-field="fieldname123"></span>
and edit the equation:
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.
Hello, with this code, many of my calculation problems have been solved.
(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.
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)
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
Thanks.
- This reply was modified 1 year, 7 months ago by klingbeil.
- This reply was modified 1 year, 7 months ago by klingbeil.
- This reply was modified 1 year, 7 months ago by klingbeil.
- This reply was modified 1 year, 7 months ago by klingbeil.
- This reply was modified 1 year, 7 months ago by klingbeil.
- This reply was modified 1 year, 7 months ago by klingbeil.
Hello @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:
Conclusion : <span data-calculated-field="fieldname123"></span>
And the HTML Content field fieldname444 with content:
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
* You can modify the text from the equation’s code. Enclose the text into a tag as follows:
<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:
(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:
IF(fieldname555 == 'A', 'Conclusion', 'Conclusion 2')
And edit the summary text as follows:
<span data-calculated-field="fieldname666"></span> : <span data-calculated-field="fieldname123"></span>
Best regards.
Thanks a lot
My last question..(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;
(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.
(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; })();
(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.
Excellent !!!!
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..(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.
<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.Hello @klingbeil
Please, edit the tag as follows:
<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
withdata-cff-field
Best regards.
Hello, it didn’t.
In fact, in the return field;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?
ThanksAdditional Note: Video Link
Hello @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.
(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.
You’re a little confused, let me clear it up.
The code at the bottom multiplies 2 fields and writes the result.
dikalanhesaplama = PREC(fieldname1 * fieldname2, 2, true);
karealanhesaplama = PREC(fieldname1 * fieldname2, 2, true);
I get these results if the fieldname criterion is A
(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]; })();
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
- The topic ‘Dropdown Calculator’ is closed to new replies.