• Resolved gregorr64

    (@gregorr64)


    Is it possible to compare a users selection by text rather than values as I need to compare colours to see if they match, but the values are holding the Colour Bands.

    For example there are multiple selections with the value of 1 whereas there is only one selection called “Blue”.

    Is this possible or should I use an If statement to assign the Band numbers later on?

    Thanks,
    Gregor

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter gregorr64

    (@gregorr64)

    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

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter gregorr64

    (@gregorr64)

    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

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter gregorr64

    (@gregorr64)

    Hi,

    Yeah I changed it to the corresponding fields. I’ll try that out justnow!

    Thanks,
    Gregor

    Thread Starter gregorr64

    (@gregorr64)

    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

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter gregorr64

    (@gregorr64)

    Ahhh right, thanks for the help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Compare Selection Text rather than Value’ is closed to new replies.