• Resolved anoutiproductions

    (@anoutiproductions)


    So I made this pet food calculator and everything is great. However, I want to change the field name of x[2] when someone selects a certain type of pet in X[1].

    For instance, if someone selects Puppy, I want X[2] field name to be ‘Age in weeks’ and if they select Dog, the same fied should change to ‘Age in years’. The change needs to happen without having to click on calculate. I would like to keep calculate button intact to show the result only once clicked, but ony change the name of X[2] updon selecting the pet type. below is my code:

    let type = x[1];
    let age = x[2];
    let weight = x[3];
    let activity = x[4];
    
    //Puppy
    if(type == '1') {
    if(age <11){y[1] = roundVal(0.1 * weight * 1000)} else if(age >10 && age <17){y[1] = roundVal(0.08 * weight * 1000)} else if(age >16 && age <21){y[1] = roundVal(0.07 * weight * 1000)} else if(age >20 && age <25){y[1] = roundVal(0.06 * weight * 1000)} else if(age >24 && age <37){y[1] = roundVal(0.05 * weight * 1000)} else if(age >36 && age <57){y[1] = roundVal(0.04 * weight * 1000)} else if(age >56 && age <69){y[1] = roundVal(0.03 * weight * 1000)}
    else{y[1] = 'Please Fill in all Details'}
    }
    
    //Kitten
    else if(type == '2') {
    if(age <11){y[1] = roundVal(0.1 * weight * 1000)} else if(age >10 && age <17){y[1] = roundVal(0.08 * weight * 1000)} else if(age >16 && age <21){y[1] = roundVal(0.07 * weight * 1000)} else if(age >20 && age <25){y[1] = roundVal(0.06 * weight * 1000)} else if(age >24 && age <37){y[1] = roundVal(0.05 * weight * 1000)} else if(age >36 && age <57){y[1] = roundVal(0.04 * weight * 1000)} else if(age >56 && age <69){y[1] = roundVal(0.03 * weight * 1000)}
    else{y[1] = 'Please Fill in all Details'}
    }
    
    //Dog
    else if(type == '3') {
    if(activity == '1'){y[1] = roundVal(0.02 * weight * 1000)}
    else if(activity == '2'){y[1] = roundVal(0.03 * weight * 1000)}
    else if(activity == '3'){y[1] = roundVal(0.04 * weight * 1000)}
    else if(activity == '4'){y[1] = roundVal(0.05 * weight * 1000)}
    else{y[1] = 'Please Fill in all Details'}
    }
    
    //Cat
    else if(type == '4') {
    if(activity == '1'){y[1] = roundVal(0.02 * weight * 1000)}
    else if(activity == '2'){y[1] = roundVal(0.03 * weight * 1000)}
    else if(activity == '3'){y[1] = roundVal(0.04 * weight * 1000)}
    else if(activity == '4'){y[1] = roundVal(0.05 * weight * 1000)}
    else{y[1] = 'Please Fill in all Details'}
    }
    
    else{y[1] = 'Please Fill in all Details'}

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor DmtLo

    (@lobov)

    Hello.

    1. Add the next code in Formula:

    if(type === 1 || type === 2) {
    	label[2].text('Age in weeks');
    } else {
    	label[2].text('Age in years');
    }

    2. Check the option ‘Calculate when the parameters are changed.’

    Thread Starter anoutiproductions

    (@anoutiproductions)

    Thank you for your speedy response!

    This works, and I have tried it before, however, it shows the results when parameters are changed too which is what the client does not want. They only want to change the field label prior to showing results. Besides, when calculate when parameters are changed is checked, the input fields keep switching to the next one before completing the input.

    Is there a way to change field label without showing the result? The result should only show once “calculate” is hit

    Thanks Again! Great plugin btw

    Plugin Contributor DmtLo

    (@lobov)

    OK.

    Use the next code in Formula:

    function changeAge() {
    	let type = field[1].value;
    	if(type === '1' || type === '2') {
    		label[2].text('Age in weeks');
    	} else {
    		label[2].text('Age in years');
    	}
    }
    changeAge();
    field[1].addEventListener('change', changeAge);
    

    And check the option ‘Make a calculation when loading the form’.

    Thread Starter anoutiproductions

    (@anoutiproductions)

    Fantastic. Worked like a charm. Was able to develop it even further! Love the plugin. I will push this and all your template calculators to all my clients.

    Plugin Contributor DmtLo

    (@lobov)

    Thank you so much for your wonderful feedback!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.