Hello @gregorr64,
Actually, the alternative to use depends of your project. Please, describe exactly the situation (with the names of the fields that participate), the current equation, and the equation you want to implement.
Best regards.
The user chooses a worktop colour out of a list. This worktop colour is assigned a band colour between 1-5 for pricing. They can then choose if they want upstands and what colour they would like them (priced in bands also).
However if they choose the same colour of worktop and upstands, then they don’t need to buy an extra sheet of material to make them therefore it is cheaper.
Right now I’ve implemented it so that it’s using the value (1-5) to compare the colours however this would mean that they could pick white and grey (both band 1) and would get the discount even though they shouldn’t as the colours are different.
I know that I can implement it by using an IF statement to assign the band number once the colours have been compared however this adds a lot of extra risk of errors.
This is why I was wondering if there is any way that I could compare the colours by name so that it would definitely only allow the discount if both colours are the same.
Thanks,
Gregor
Hello @gregorr64,
I’ll try to describe the process with an example.
Assuming there are two dropdown fields: fieldname1 and fieldname2, and you want to compare the texts of choices selected, and use their values too:
(function(){
var v1 = fieldname1, v2 = fieldname2,
t1 = jQuery('[id*="fieldname'+'1_"] option').attr('vt'),
t2 = jQuery('[id*="fieldname'+'2_"] option').attr('vt');
/* Now you can use the values of fields into the variables v1 and v2, and the texts of the selected choises t1 and t2 */
})()
Best regards.
Hi,
I tried it out like this:
(function(){
var v1 = fieldname1, v2 = fieldname2,
t1 = jQuery(‘[id*=”fieldname’+’1_”] option’).attr(‘vt’),
t2 = jQuery(‘[id*=”fieldname’+’2_”] option’).attr(‘vt’);
if(t1== t2) return 1;
return 0;
})()
However it didn’t appear to work as expected. Have I done something wrong?
Thanks,
Gregor
Hello @gregorr64,
You should use the corresponding fields’ names in your form, I’ve used the fieldname1 and fieldname2 only to describe the process.
Furthermore, I’ve an error in my code (my apologies), the correct would be:
(function(){
var v1 = fieldname1, v2 = fieldname2,
t1 = jQuery('[id*="fieldname'+'1_"] option:selected').attr('vt'),
t2 = jQuery('[id*="fieldname'+'2_"] option:selected').attr('vt');
if(t1== t2) return 1;
return 0;
})()
Best regards.
Hi,
Yeah I changed it to the corresponding fields. I’ll try that out justnow!
Thanks,
Gregor
Hi,
That works perfectly, thanks for the help!
Just another query – how do I go about rounding the final total to 2 decimal places? I’ve used ROUND(fieldname33,0.01) justnow but it sometimes gives me weird outputs such as
rounding £364.34 to £364.34000000000003.
Thanks,
Gregor
Hello @gregorr64,
Use the “PREC” operation instead ROUND. PREC(X, Y) rounds the number X with Y decimal places, so, the correct equation would be:
PREC(fieldname33,2)
Best regards.
Ahhh right, thanks for the help!