• Resolved chadtesting

    (@chadtesting)


    So I want to do the following with this calculation:

    (function(){
    var values = [fieldname2,fieldname6,fieldname73,fieldname321,fieldname325,fieldname74],
    total = 0,
    counter = 0;
    for(var i in values)
    {
    if(values[i]) counter++;
    total += values[i];
    }
    var result = PREC((counter)?total/counter:0, 1);

    If (value>90) then <fieldname1> == “A+”
    If (value<=80 && value>=90) then <fieldname1> == “A”

    I want to output this to an HTML field, but also display this output (A+, A, etc) directly in the calculated field, so I can display it in my e-mail. So far I’ve had to use show/hide logic, but I think it would be easier if I can just display the variable field with the result “A+” or “A” straight to the <block><endblock> rather than repeating it for every possible option.

    Thank you

    • This topic was modified 8 years, 1 month ago by chadtesting.
    • This topic was modified 8 years, 1 month ago by chadtesting.
    • This topic was modified 8 years, 1 month ago by chadtesting.
    • This topic was modified 8 years, 1 month ago by chadtesting.
    • This topic was modified 8 years, 1 month ago by chadtesting.
    • This topic was modified 8 years, 1 month ago by chadtesting.
    • This topic was modified 8 years, 1 month ago by chadtesting.
    • This topic was modified 8 years, 1 month ago by chadtesting.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter chadtesting

    (@chadtesting)

    Also, check your e-mail please. I would like to get an hour of your time to work through this calculation fully as it’s going to be a bit more complex.

    Plugin Author codepeople

    (@codepeople)

    Hello,

    You simply need something similar to:

    (function(){
    var values = [fieldname2,fieldname6,fieldname73,fieldname321,fieldname325,fieldname74],
    total = 0,
    counter = 0,
    result, letter;
    
    for(var i in values)
    {
    if(values[i]) counter++;
    total += values[i];
    }
    result = PREC((counter)?total/counter:0, 1);
    if( 90 < result ) letter = "A+";
    else letter "A";
    jQuery('.result').html( letter );
    return letter;
    })()

    Best regards.

    Thread Starter chadtesting

    (@chadtesting)

    Hmm, that looks fine to me but it’s not outputting the value. The calculated field should output the (letter) value “A+” or “A” depending on what the value of (result) is, correct?

    result is working correctly, but something isn’t working when converting it to letter.

    Plugin Author codepeople

    (@codepeople)

    Hello,

    I’m sorry, I’ve a typo in the code I sent you previously, the assignment symbol in the “else” statement:

    (function(){
    var values = [fieldname2,fieldname6,fieldname73,fieldname321,fieldname325,fieldname74],
    total = 0,
    counter = 0,
    result, letter;
    
    for(var i in values)
    {
    if(values[i]) counter++;
    total += values[i];
    }
    result = PREC((counter)?total/counter:0, 1);
    if( 90 < result ) letter = "A+";
    else letter = "A";
    jQuery('.result').html( letter );
    return letter;
    })()

    Best regards.

    Thread Starter chadtesting

    (@chadtesting)

    I’m a bit embarrassed I couldn’t figure that out for myself. Code works. Thank you.

    Now for the last step. I need to hide the calculated field from my form while still displaying the output in my e-mail. Currently when I hide my calculated form from the page, the e-mail will not pick it up.

    I am outputting it to an HTML field to display on my form, but you cannot display those in an e-mail. I don’t think there’s a way to output this value to any other field that will display and also look nice.

    So the only thing I can assume is that we need to somehow hide the calculated field without actually hiding it.

    That is unless you can remove the border around a calculated field and format it like an HTML field. In that case I will use the calculated field for everything.

    • This reply was modified 8 years, 1 month ago by chadtesting.
    • This reply was modified 8 years, 1 month ago by chadtesting.
    Plugin Author codepeople

    (@codepeople)

    Hello,

    You simply should tick the property: “Hide Field From Public Page” in the calculated field, and the calculated field should not be a dependent field.

    Best regards.

    Thread Starter chadtesting

    (@chadtesting)

    Oh wow, it does work. My apologies, I thought if I hid the calculated field from the public page that the it wouldn’t show up in my e-mail.

    It turns out that it does. Thanks!

    • This reply was modified 8 years, 1 month ago by chadtesting.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Output unique text to an HTML field based on result of a calc’ is closed to new replies.