Dropdown, different values for database/e-mail, form, calculator.

Use different dropdown values for database, email, form display, and calculator in ChronoForms.

Overview

The issue arises because the dropdown format requires distinct values for database storage, email content, form display, and a calculator widget, but the standard setup only supports two values separated by an equals sign.
Implement custom JavaScript to extract numeric values from the dropdown selections for the calculator, bypassing the built-in widget and handling the calculation directly.

Answered
st stadions11 12 Jul, 2022
Dropdown in CF6, for example:
Green apple, 10$=Green apple, extra sour, extra big, 10$
Red apple, 20$=Red apple, extra sweet, extra small, 20$
Nothing, 0$=I don't want an apple, 0$

The value before the equation is saved in the database and sent in the e-mail (Green apple, 10$).
The value after the equal sign is displayed in the form (Green apple, extra sour, extra big, 10$).
I still need a third value for the calculator, a pure integer number (10). This value should come to the calculator via the Events tab from the Dropdown.
Yes, for the correct operation of the widget calculator there must be before the equation only a number. But that is not enough for the recipient of the email.
Vicious circle for me...
Gr GreyHead 14 Jul, 2022
Hi stadions,

You will need some custom code. Either in JavaScript to create a new value without the $ for use in your calculator; or you can remove the $ from the dropdown and use custom PHP to re-add it before the data is saved or emailed.

Bob
st stadions11 14 Jul, 2022
Thanks Bob!
I'm flirting with both options, but both have a snag
1. PHP - The values before the equation must not be the same, because they actually are IDs.
2. JS - I will somehow create a script to "trim" the value, but I don't know where to put it. I pass the values to the calculator widget via the Events tab. TriggeringEvent=Change, Triggered action=Add to, Affected elements CSS selectors, example: #id, name, .class = total12. ... and the Widget Calculator displays total12 online content.

I can't post pictures jpg or png here, why?
Gr GreyHead 16 Jul, 2022
Hi stadions11,

Leaving off the $ sign shouldn't stop the ids being unique???

Sorry, I have no idea why there is a problem with uploads here. It seems to work for a while, then fail again :-(

Bob
st stadions11 19 Jul, 2022
Answer
I ended up not using the built-in calculator widget.
I put this custom JS and it works:

$("#select13,#select14").on("change", function(){
$("#sum").text(parseInt( $("#select13").val().replace(/[^\d]/g, '')) + parseInt($("#select14").val().replace(/[^\d]/g, '')));
});

Bob, thanks for your help
This topic is locked and no more replies can be posted.