• Resolved angie1357

    (@angie1357)


    I have 3 different products and i’ve assigned the value 1, 2, & 3 to them as hidden field types.

    The user needs to be able to tick a feature and the output will tell them which product to get.

    I found a thread about changing the code in the module_public.js to then output the text:

    return isFinite( v ) || /\d{2}[\/\-\.]\d{2}[\/\-\.]\d{4}/.test( v ) || /Professional Website|Premium Website|Ultimate Website/i.test( v );

    This seems to work, but it’s only picking up the first text, “Professional Website”

    My calculated field equation looks like this:

    (function(){

    if(fieldname1 <= 1) return fieldname4;

    if(fieldname1 <= 2) return fieldname6;

    if(fieldname1 <= 3) return fieldname7;

    })();

    (function(){

    if(fieldname4 <= 1) return “Professional Website”;

    if(fieldname6 <=2) return “Premium Website”;

    if(fieldname7 <= 3) return “Ultimate Website”;

    })();

    Please can you tell me where i’m going wrong?

    Thanks
    Angie

    https://www.ads-software.com/plugins/calculated-fields-form/

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

    (@codepeople)

    Hi,

    You can use the following validation rules:

    return isFinite( v ) || /\d{2}[\/\-\.]\d{2}[\/\-\.]\d{4}/.test( v ) || /((Professional\s+Website)|(Premium\s+Website)|(Ultimate\s+Website))/i.test( v );

    or simply replace all the validation rule like follow:

    return (typeof v != ‘undefined’);

    Best regards.

    Thread Starter angie1357

    (@angie1357)

    Thanks for your quick response. it seems like i’ve finally got it working – to an extent.

    What i now need to figure out is to get it to output only the highest value as well as to hide the outputs that pull through below the Recommended Website Package field.

    https://showmeonlinemedia.co.za/test/

    Plugin Author codepeople

    (@codepeople)

    Hi,

    I don’t know exactly the behavior you want in the form, but if you want hide some fields of the form, you only should add an class name to the fields to hide, through the “Add Css Layout Keywords” attribute, for example: my_class, and then define the new class in any of CSS files of your website:

    .my_class{display:none;}

    Best regards.

    Thread Starter angie1357

    (@angie1357)

    thanks, i’ve done that ans it works well, but how do I make the output the highest number and not the lowest.

    For example, if someone has ticked 3 boxes, one with the 1 value, and two with the 2 value, when they push calculate, it says the result is 1 (I want it to pick the highest number and output that).

    I have tried ‘max(fieldname19,fieldname20,fieldname21)’ but this did not work.

    Please advise, thanks agian

    Plugin Author codepeople

    (@codepeople)

    Hi,

    The use of the operation “max” is correct, and should return the maximum of the three fields. Could you tell where are you using the max operation, please? I’ve checked your form in:

    https://showmeonlinemedia.co.za/test/

    and I can’t detect where the operation is used.

    Best regards.

    Thread Starter angie1357

    (@angie1357)

    I had taken it out beacuse when i put the max(fieldname19,fieldname20,fieldname21) into the equation box in the Calculated Field (recommended Website Package) t works, but it then only returns the value 1, 2 or 3, instead of the words/descriptions connected to the value, Proffesional, Premium, ultimate.

    Here is what my equation currently looks like: (including the max)

    (function(){

    if(fieldname1 <= 1) return fieldname19;

    if(fieldname1 <= 2) return fieldname20;

    if(fieldname1 <= 3) return fieldname21;

    })();

    (function(){

    if(fieldname19) return “Professional Website”;

    if(fieldname20) return “Premium Website”;

    if(fieldname21) return “Ultimate Website”;

    })();

    max(fieldname19,fieldname20,fieldname21)

    Plugin Author codepeople

    (@codepeople)

    Hi,

    You have not created an equation, You have merged three equations in one. First, you should determine of the value that you want display in the calculated field, if you want display only the maximum value between fieldname19, fieldname20 and fieldname21, the equation is simply:

    max(fieldname19,fieldname20,fieldname21)

    Best regards.

    Plugin Author codepeople

    (@codepeople)

    Hi,

    Analyzing your form again, I think you have complicated your form too much, because if you use radiobuttons, in place of checkboxes, in the field: “How many pages do you need?”, all will be reduced to the equation:

    (function(){
    if(fieldname19) return “Professional Website”;
    if(fieldname20) return “Premium Website”;
    if(fieldname21) return “Ultimate Website”;
    })();

    You are trying to simulate an exclusive selection, but with checkboxes, the correct control in this case is the radiobutton.

    Best regards.

    Thread Starter angie1357

    (@angie1357)

    Hmmm…ok, i’ve changed the pages one to radio buttons.

    If i use just this equation:
    max(fieldname19,fieldname20,fieldname21)
    Then it shows only the number value, 1,2,3 (correctly the highest one)

    If i use just this equation:
    (function(){
    if(fieldname19) return “Professional Website”;
    if(fieldname20) return “Premium Website”;
    if(fieldname21) return “Ultimate Website”;
    })();
    Then all results are “Professional”

    How do I combine this in one equation, to choose the highest value and then convert it into the description of it?

    Thanks ??

    Plugin Author codepeople

    (@codepeople)

    Hi,

    If you want combine both equations the solution would be:

    (function(){
    var m = MAX(fieldname19, fieldname20, fieldname21);
    if(m==fieldname19) return “Professional Website”;
    if(m=fieldname20) return “Premium Website”;
    if(m==fieldname21) return “Ultimate Website”;
    })();

    You are using now two equations associated to the calculated fields.

    Best regards.

    Thread Starter angie1357

    (@angie1357)

    Thanks, but it does not work. It does not return any value now.

    Thread Starter angie1357

    (@angie1357)

    Correction, it works! ??

    there was a = missing in the equation

    Thanks again

    Thread Starter angie1357

    (@angie1357)

    Is there a way that the output “recommended Website Package” field can stay empty until a checkbox is ticked? currently it is displaying the least value before anything has been ticked – which also then eliminates the need for the calculate button, as it is visibly calculating and outputting all the time.

    Plugin Author codepeople

    (@codepeople)

    Hi,

    You can use conditional statements in the equations. For example, if you have 3 fields: fieldname1, fieldname2 and fieldname3, and you want display a value in the calculated field if at least one of previous fields includes a value, the equation would be:

    (function(){
    if(fieldname1 || fieldname2 || fieldname3)
    {
    //….
    }
    else
    {
    return ”;
    }
    })()

    You should use the logic of the previous equation in your form.

    Best regards.

    Thread Starter angie1357

    (@angie1357)

    Hi again, it has come to my attention that the plugin does not work in Firefox. Please advise how I can fix this? Thanks

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Text output’ is closed to new replies.