• Resolved romanovwp

    (@romanovwp)


    Hi guys,
    I’ve been struggling with the following: I want to make it easier for users of http://www.asian-translations.com to get a quotation for translation work. Created 2 dropdown menus: 1x source language, and 1x destination language, and 1 additional numeric field (“number of words in your document”). Visitor should be able to select translation from English (source language dropdown) to Thai (destination language dropdown), then enter 1,000 as word count, and get a quotation based on USD x.xx/word. Issue is that the value of the source language cannot be the same at all times. Example: translation from English to Thai is USD 0.50/word, yet from English to Chinese is USD 0.75. I know I could fit all combinations into 1 dropdown menu, and then attached a price/word to that value, but given the future expansion in language offerings, I need to have it as flexible as possible for the visitors.
    Tried to work with a function for conditional calculations in the ‘Set equation’ field, but to no avail…

    The page I need help with: [log in to see the link]

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

    (@codepeople)

    Hello @romanovwp,

    The process is simple, but you need to create an array of javascript objects.

    I’ll try to illustrate the process with an example:

    Your form includes two dropdown field (fieldname1, and fieldname2) with the languages: A, B, and C respectively, and a number field (fieldname3) for entering the number of words. I will assume too that the translation cost by word is as follows:

    From A to B = 0.75
    From A to C = 0.85
    From B to C = 0.60

    I will assume that the translation cost is the same in the other direction, however, it is very simple to extend the example to use a different cost for new pairs of languages.

    I will define as part of the equation an array of objects similar to:

    var data = [
      {
         'from' : 'A',
         'to' : 'B',
         'cost' : 0.75
      },
      {
         'from' : 'A',
         'to' : 'C',
         'cost' : 0.85
      },
      {
         'from' : 'B',
         'to' : 'C',
         'cost' : 0.60
      }
    ];

    now the equation would be:

    (function(){
        var data = [
          {
             'from' : 'A',
             'to' : 'B',
             'cost' : 0.75
          },
          {
             'from' : 'A',
             'to' : 'C',
             'cost' : 0.85
          },
          {
             'from' : 'B',
             'to' : 'C',
             'cost' : 0.60
          }
        ];
    
        for(var i in data)
        {
            if((data[i]['from'] == fieldname1 && data[i]['to'] == fieldname2) || 
               (data[i]['from'] == fieldname2 && data[i]['to'] == fieldname1)
            )
            {
               return data[i]['cost']*fieldname3;
            }
        }
        return 'It is not required a translation';
    })()

    I’m sorry, but the support service does not cover the implementation of the users’ projects (forms or formulas). If you need additional support implementing your equations, I can offer you a custom coding service through my personal website:

    https://cff.dwbooster.com/customization

    Best regards.

    Thread Starter romanovwp

    (@romanovwp)

    Thank you so much for your quick reply, you are awesome with your support!! I’ll work my way through it, thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Assigning conditional values to dropdown selections’ is closed to new replies.