Unable to update field prior to clicking on calculate
-
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)
Viewing 5 replies - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.