Hi,
In javascript the “AND” operator is represented by &&, furthermore you should close each opened symbol “{“. So, the equation would be:
(function(){
if(fieldname7==1 && fieldname11==1){
return (66+fieldname5*13.7+fieldname4*5-fieldname2*6.8)*1.2;
}
if(fieldname7==1 && fieldname11==2){
return (66+fieldname5*13.7+fieldname4*5-fieldname2*6.8)*1.375;
}
if(fieldname7==1 && fieldname11==3){
return (66+fieldname5*13.7+fieldname4*5-fieldname2*6.8)*1.55;
}
if(fieldname7==1 && fieldname11==4){
return (66+fieldname5*13.7+fieldname4*5-fieldname2*6.8)*1.725;
}
if(fieldname7==1 && fieldname11==5){
return (66+fieldname5*13.7+fieldname4*5-fieldname2*6.8)*1.9;
}
if(fieldname7==2 && fieldname11==1){
return (655+fieldname5*9.6+fieldname4*1.8-fieldname2*4.7)*1.2;
}
if(fieldname7==2 && fieldname11==2){
return (655+fieldname5*9.6+fieldname4*1.8-fieldname2*4.7)*1.375;
}
if(fieldname7==2 && fieldname11==3){
return (655+fieldname5*9.6+fieldname4*1.8-fieldname2*4.7)*1.55;
}
if(fieldname7==2 && fieldname11==4){
return (655+fieldname5*9.6+fieldname4*1.8-fieldname2*4.7)*1.725;
}
if(fieldname7==2 && fieldname11==5){
return (655+fieldname5*9.6+fieldname4*1.8-fieldname2*4.7)*1.9;
}
})()
Best regards.
Hi,
Have tried that but it still does not work. Any suggestions?
Cheers
Hi,
The URL you sent me includes a form that is not generated with our plugin.
Could you send me the URL to the webpage where was inserted the form created with our plugin to check the equation in detail, please?
Best regards.
Hi
Thanks again for your reply. Unfortunately my website is not live so I cannot link you to the calculator I am referring to.
Here are further details that may assist
fieldname2(age) = number
fieldname7(gender) = dropdown, where male = 1 and female = 2
fieldname4(height) = number
fieldname5(weight) = number
fieldname11(activity factor) = radio buttons where level of activity has corrresponding activity factor/value varying from 1 to 5
fieldname12(TDEE) is the calculated field in which I am referring to
So far, i am inputting the code you’ve mentioned but it does not calculate. see uploaded image:
View post on imgur.com
Hi,
In principle, the equation should work, but I need to check the form in the page, to detect if exists any issue.
Best regards.
I’m having trouble with the conditional fields too.
I’m trying to set a formula where if they select from a dropdown menu, each option in the dropdown results in a different calculation.
The formula I’m trying to use is this:
(function(){
if(fieldname3==1){
return (fieldname5*10);
if(fieldname3==2){
return (fieldname5*100);
}
})()
The fieldname3 is the first field which is the dropdown, then fieldname5 is the second field the user fills out. But it’s not working.
AND
When I select from the dropdown, that field completely disappears. Could you please help? Thanks very much.
See calculator here:
http://www.americandatanetwork.com/test-3/
Hi,
You’ve forgotten a “}” symbol for closing the first conditional statement. The correct is:
(function(){
if(fieldname3==1){
return (fieldname5*10);
}
if(fieldname3==2){
return (fieldname5*100);
}
})()
Best regards.
I am also trying to build a field form for a TDEE formula. Im trying to create a form using two formulas. I am new to javascript and have done the best I could to base my formula on those above. I understand how to write equations but would like to get it checked. Also, how do I make a button to calculate this equation and what code do I use for that?
(function(){
if(fieldname9==1 && fieldname7==1 && fieldname8==1){
return (66+fieldname5*13.7+fieldname4*5-fieldname3*6.8*1.2;
}
if(fieldname9==1 && fieldname7==1 && fieldname8==2){
return (66+fieldname5*13.7+fieldname4*5-fieldname3*6.8*1.375;
}
if(fieldname9==1 && fieldname7==1 && fieldname8==3){
return (66+fieldname5*13.7+fieldname4*5-fieldname3*6.8*1.55;
}
if(fieldname9==1 && fieldname7==1 && fieldname8==4){
return (66+fieldname5*13.7+fieldname4*5-fieldname3*6.8*1.725;
}
if(fieldname9==1 && fieldname7==1 && fieldname8==5){
return (66+fieldname5*13.7+fieldname4*5-fieldname3*6.8*1.9;
}
if(fieldname9==1 && fieldname7==2 && fieldname8==1){
return (655+fieldname5*9.6+fieldname4*1.8-fieldname3*4.7)*1.2;
}
if(fieldname9==1 && fieldname7==2 && fieldname8==2){
return (655+fieldname5*9.6+fieldname4*1.8-fieldname3*4.7)*1.375;
}
if(fieldname9==1 && fieldname7==2 && fieldname8==3){
return (655+fieldname5*9.6+fieldname4*1.8-fieldname3*4.7)*1.55;
}
if(fieldname9==1 && fieldname7==2 && fieldname8==4){
return (655+fieldname5*9.6+fieldname4*1.8-fieldname3*4.7)*1.725;
}
if(fieldname9==1 && fieldname7==2 && fieldname8==5){
return (655+fieldname5*9.6+fieldname4*1.8-fieldname3*4.7)*1.9;
}
if(fieldname9==2){
return (370+21.6*(fieldname5(fieldname5*(fieldname10/100))))
}
})()
*Note the last equation is the second formula, I am not sure if thats correct because I am trying to get a number converted into a percentage. User will input an integer and I’d like the code to convert it to a percentage.
Now that I look at it it needs a –
if(fieldname9==2){
return (370+21.6*(fieldname5-(fieldname5*(fieldname10/100))))
}
})()
Hi,
Your equation has some errors, for example in all these lines of code:
return (66+fieldname5*13.7+fieldname4*5-fieldname3*6.8*1.2;
return (66+fieldname5*13.7+fieldname4*5-fieldname3*6.8*1.375;
return (66+fieldname5*13.7+fieldname4*5-fieldname3*6.8*1.55;
return (66+fieldname5*13.7+fieldname4*5-fieldname3*6.8*1.725;
return (66+fieldname5*13.7+fieldname4*5-fieldname3*6.8*1.9;
You’ve opened parenthesis, but you have never closed them.
Best regards.