Assign multiple values to Single dropdown selection
-
Hi,
How do you assign multiple values to a Single dropdown selection. Assigning 1 value is easy, but I’m not sure how to assign 2 separate values to one selection.
For e.g. on my form:
1) Select your Country (I have offered a list of around 15 countries)
e.g. user chooses Malaysia – I have already assigned a value of 0.20How do I also assign a value of (e.g. 2.5 to Malaysia also) without asking them to enter their country again?
Thank you!
https://www.ads-software.com/plugins/calculated-fields-form/
-
Hi,
I’m sorry, I don’t know exactly what you are implementing, but in HTML the options in a
<select>
tag only allow a text and a value.I’ll try to explain an alternative mode with a simple example. Suppose you have two fields, one of them with a countries list, that includes Malaysia (I’ll call to this field as fieldname1), and another field for conveyance, with the possible values: boat, and aircraft (I’ll call to this field as fieldname2).
Then, in your equation would be possible to use conditional statements to get the correct value in function to the options selected in the previous fields:
(function(){ var f1 = fieldname1, f2 = fieldname2; if(f1=='Malaysia' && f2=='aircraft') return 20; if(f1=='Malaysia' && f2=='boat') return 25; })()
Best regards
Hi,
Thanks for your help. I still have not resolved the first issue, but can put it on hold for now. Another question:
How do I use reference fieldnames in a calculated field box? What I want to achieve is a user will select a list of currencies from a dropdown (e.g. USD$) and at the end the output result box I want to show a calculated amount in USD$
Hi,
In this case I recommend let in blank the attributes: prefix and suffix of the calculated field, and add the currency symbol in the equation.
For example, if the DropDown field with the currencies list is the fieldname3, and your current equation is fieldname1*fieldname2, you should modify it like:
fieldname3+(fieldname1*fieldname2)
Tip: Use parenthesis between the currency fields and the rest of the equation, because the currency field is a text, and the rest of the equation is a mathematical operation, but unfortunately javascript overloads the “+” operator and is needed increase the priority of the mathematical operation with parenthesis.
Best regards.
Hi Codepeople,
Thanks for your solution – it worked but in this case inserting the “fieldname3” into the equation formula breaks the formatting. E.g. now it shows AUD200000.10 instead of $200,000.10 previously.
Also I have another question: Is it possible to include a ‘calculate’ function into the ‘Submit’ button? I need to do this to show the result on the ‘thank you’ page and I am NOT using ‘eval dynamically the equations’
Hi,
Answering to your first question:
Please, uses an internal function, that is not part of modules documentation, like follow:
fieldname3+fbuilderjQuery.fbuilder.calculator.format(fieldname1*fieldname2,{'groupingsymbol': ','})
The “format” operation belongs to the object: fbuilderjQuery.fbuilder.calculator
The first parameter is the number you want to format, in this example fieldname1*fieldname2, and the second parameter is a literal object with the configuration, for example, in this example the second parameter indicates the use of comma symbol as thousands separator.
About your second question, If you don’t want to display the calculated field in the form, only in the “Thank you” page, you simply should select the calculated field and tick the option: “Hide Field From Public Page”, and that’s all.
Best regards.
Hi,
I also have a question, How do i hide the 0 number when there is nothing being calculated? The problem is that 0 is being shown even if there is no calculation being done.
For example i have an optional result/calculation field which has this format
fieldname14*.51+fieldname14 where as fieldname14 is the value that is optional to add a number on it.What i want is that if they don’t put anything there on the field instead of 0 being shown a blank field would be shown instead.
Thanks,
ReyHi,
You can modify the equation using a conditional statement, as follows:
IF(fieldname14, fieldname14*.51+fieldname14, '')
Best regards.
Great,
It’s working now, thank you for the swift response.
Oh and another thing when using this equation:fieldname12+fieldname10*51/100+3000
where fieldname12 is currency and fieldname10 is 3000 for example, the equation works until you divide it by 100 then the last part which is adding the 3000 results in
15303000
It just displays the two numbers and doesn’t seem to add it together which should result in 4530.
Thanks,
ReyHi,
Please, modify your equation like follow:
fieldname12*1+fieldname10*51/100+3000
However, could you send me the link to your form to check the fields’ definitions, please?
Best regards.
Hi,
Sure it’s for a client i’m currently working at, the website link would be https://www.swifterm.com you can see it on the Calculation part.
Thanks,
ReyHi,
So yep it’s working now but only when i choose the currency to $ but when i choose the currency for the £ pounds sign, it doesn’t seem to show up?
Regards,
ReyHi,
The issue is simple, fieldname12 is not a currency field, is a radio field where its values are the currency symbols, if you add it to the rest of the equation without using parenthesis you are concatenating the number 3000 as a text, and not as part of a mathematical operation. So, please, forget the previous equation, the correct one, in function to the structure of your fields would be:
fieldname12+(fieldname10*51/100+3000)
Pay attention: The snippet of code fieldname12*1 has been converted to fieldname12, because the fieldname12 is a text, furthermore, I’ve included parentheses to evaluate first the mathematical operations, and then, concatenate the result the text with the currency symbol.
Best regards.
Hi,
Thank you that solved the problem big time.
Last 2 question and final if that would be alright is that when I am using the currency $ it doesn’t seem to show itself? Should i change the radio field to currency? if so how do i add multiple currency to choose from?
and lastly how do i use a validation for the Company URL and email? for example the email would be [email protected] and the website is https://www.yourwebsite.com, could i add something there to compare the two? so that if the last part of the email which is @yourwebsite.com is different from the company URL it would return an error?
I think this would be the last problem i am encountering, I would like to tell you that the client is very much pleased in buying the said software which does what they wanted.
Thanks so much for the support,
ReyHi,
The validation you need is not included in the plugin, because it is a particular behavior to your project, however, you can compare the texts through an equation associated to a calculated field.
For example, you can insert a calculated field as an auxiliary field, as the auxiliary field is not relevant in the form interface, you can tick the option: “Hide Field From Public Page”, to prevent the form be submitted if the validation is fails, tick the option: “Required”, and returns a value from the equation only if the comparison is valid, or an empty text if not.
For example, if the field for the website’s URL is the fieldname1, and the field for the email address is the fieldname2, a valid equation to use for comparing would be:
(function(){ if(fieldname1 && fieldname2) { var url = jQuery.trim(fieldname1).toLowerCase(); var parts = jQuery.trim(fieldname2).toLowerCase().split( '@' ); if(parts.length == 2 && url.indexOf(parts[1]) != -1) { return 1; } else { alert( 'The email address does not belong to the website' ); return ''; } } })()
Important Note: I’m sorry, but the support service does not include the development of custom formulas, but if you are needing additional help with your equations, don’t hesitate in contact me through my private support page, asking for a custom coding service.
Best regards.
How about the sign for $ not showing up when being chosen?
Thanks,
Rey
- The topic ‘Assign multiple values to Single dropdown selection’ is closed to new replies.