• Resolved iguider10

    (@iguider10)


    Hello my friends,

    Before i’m asking you, i read many of your support to others and by that i succed the correct equations ^^

    Now what i want and i didnt found the right solution due to my ignorance is how can i input the results inside a text

    For exemple I want to say : You result in points is “the score result field” which corresponds to a “The Note result field”

    the score resultat field Equation is :
    fieldname1*699/100

    The Notre result field Equation is :
    (function(){
    if(fieldname1*699/100 < 1) return 0;
    if(fieldname1*699/100 < 199) return ‘A1’;
    if(fieldname1*699/100 < 299) return ‘A2’;
    if(fieldname1*699/100 < 399) return ‘B1’;
    if(fieldname1*699/100 < 499) return ‘B2’;
    if(fieldname1*699/100 < 599) return ‘C1’;
    if(fieldname1*699/100 < 699) return ‘C2’;
    })()

    I tried in many ways to use your solution about “var result= with html” but it wont work, sorry i’m an amateur in coding

    Check this link i insert some capture screen for you : https://preparationtcf.com/staging/2560/calculer-resultat-tcf/

    Thank you so much for providing help for me and for others, you work im too much appreciated and you pluging is lovely <3

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

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

    (@codepeople)

    Hello @iguider10

    First, for optimization do not repeat the same action again and again. Assign the result of the mathematical operation to a variable and use this variable in the comparisons:

    
    (function(){
        var v = fieldname1*699/100;
        if(v < 1) return 0;
        if(v < 199) return 'A1';
        if(v < 299) return 'A2';
        if(v < 399) return 'B1';
        if(v < 499) return 'B2';
        if(v < 599) return 'C1';
        if(v < 699) return 'C2';
    })()
    

    Now, assuming you want to display this result in a text with the format: Hello, the result is …

    If you want this text into the calculated field, the equation would be simply:

    
    CONCATENATE(
        'Hello, the result is ', 
        (function(){
            var v = fieldname1*699/100;
            if(v < 1) return 0;
            if(v < 199) return 'A1';
            if(v < 299) return 'A2';
            if(v < 399) return 'B1';
            if(v < 499) return 'B2';
            if(v < 599) return 'C1';
            if(v < 699) return 'C2';
        })()
    );
    

    If you want to display the result into another field, like an “HTML Content” field. You can insert an “HTML Content” field in the form with content similar to:

    
    Hello, the result is <span class="result-here"></span>
    

    and then the equation would be similar to:

    
    jQuery('.resul-here').html(
        (function(){
            var v = fieldname1*699/100;
            if(v < 1) return 0;
            if(v < 199) return 'A1';
            if(v < 299) return 'A2';
            if(v < 399) return 'B1';
            if(v < 499) return 'B2';
            if(v < 599) return 'C1';
            if(v < 699) return 'C2';
        })()
    );
    

    Best regards.

    Thread Starter iguider10

    (@iguider10)

    Thank you so much my friend, that works perfectly amazing ^^

    Please last question, how can i show custom messages based on the result of a field ?

    For exemple results of fieldname19 can be A1 or A2 or B1 or B2 or C1 or C2, so if a student has ‘A1’ it will be shown ‘Very BAD’… if he had C2 it will be shown ‘Perfect’ i tried this equation which i found on one of your topics but it didnt work for me

    (function(){
    if(fieldname19 = 'A1') return Very BAD;
    if(fieldname19 = 'A2') return BAD;
    if(fieldname19 = 'B1') return Need to work more;
    if(fieldname19 = 'B2') return Well done;
    if(fieldname19 = 'C1) return Good job;
    if(fieldname19 = 'C2) return Perfect;
    })()

    See here i attached a picture on the page :https://preparationtcf.com/calculer-score-tv5-monde/

    Sorry for my english and thank you so much again for your help, you so kind <3

    Plugin Author codepeople

    (@codepeople)

    Hello @iguider10

    In javascript the texts’ values must be enclosed between single or double quotes. So, the equation would be:

    
    (function(){
    if(fieldname19 == 'A1') return 'Very BAD';
    if(fieldname19 == 'A2') return 'BAD';
    if(fieldname19 == 'B1') return 'Need to work more';
    if(fieldname19 == 'B2') return 'Well done';
    if(fieldname19 == 'C1) return 'Good job';
    if(fieldname19 == 'C2) return 'Perfect';
    })()
    

    Best regards.

    Thread Starter iguider10

    (@iguider10)

    Sadly this code seems to not work with me :

    (function(){
    if(fieldname19 = 'A1') return 'Very BAD';
    if(fieldname19 = 'A2') return 'BAD';
    if(fieldname19 = 'B1') return 'Need to work more';
    if(fieldname19 = 'B2') return 'Well done';
    if(fieldname19 = 'C1') return 'Good job';
    if(fieldname19 = 'C2') return 'Perfect';
    })()

    Feeling shy to ask you again, i did many ressearchs on other topics but did found the solution

    Just for information, the fieldname19 is the result of a calculation here is the code :

    jQuery('.result-here8').html(
        (function(){
            var v = fieldname17*699/80;
            if(v < 1) return ;
            if(v < 199) return 'A1';
            if(v < 299) return 'A2';
            if(v < 399) return 'B1';
            if(v < 499) return 'B2';
            if(v < 599) return 'C1';
            if(v < 699) return 'C2';
        })()
    );

    Means if for exemple the fieldname19 show B2 (after the calculation) i want in another field to show ‘Well done’

    Thank you sir and sorry for the question :/

    Plugin Author codepeople

    (@codepeople)

    Hello @iguider10

    The operator for equality is the double symbol: == because the symbol = is used for assignment:

    
    (function(){
    if(fieldname19 == 'A1') return 'Very BAD';
    if(fieldname19 == 'A2') return 'BAD';
    if(fieldname19 == 'B1') return 'Need to work more';
    if(fieldname19 == 'B2') return 'Well done';
    if(fieldname19 == 'C1) return 'Good job';
    if(fieldname19 == 'C2) return 'Perfect';
    })()
    

    Best regards.

    Thread Starter iguider10

    (@iguider10)

    Amazing
    It works like a charm ^_^
    Thank you so much my friend for the help :* have a good day
    Best wishes

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

The topic ‘Input 2 result fields inside a text’ is closed to new replies.