# WordPress.org

## Calculated Fields Form[resolved] Different values for zip code (2 posts)

1. LettuceCheese
Member
Posted 1 year ago #

Hi. I'm trying to make a form where I charge different rates depending upon a person's zip code. I thought it would be easy. I tried the following two examples (fieldname3 is where they input the zip code). I've tried a couple other things that also didn't work.

Thanks.

Example 1:
if(fieldname3 = 95124, 70, 0)
if(fieldname3 = 95125, 70, 0)
if(fieldname3 = 94085, 100, 0)
if(fieldname3 = 94086, 100, 0)
if(fieldname3 = 95116, 120, 0)

Example 2:
if(fieldname3 = 95124) v = 70;
if(fieldname3 = 95125) v = 70;
if(fieldname3 = 94085) v = 100;
if(fieldname3 = 94086) v = 100

2. codepeople
Member
Plugin Author

Posted 1 year ago #

Hi,

First, in javascript the operator for equality is "==", because the operator "=" represent the assignation.

Second, if you want use the operation IF(condition, value, value ), the equation would be:

IF(fieldname3 == 95124, 70, IF(fieldname3 == 95125, 70, IF(fieldname3 == 94085, 100, IF(fieldname3 == 94086, 100, IF(fieldname3 == 95116, 120, 0)))))

Third, if you prefer to use the equation with multiple lines, you need return a value from the equation, and define the equation with the following format:

(function(){
if(fieldname3 == 95124) return 70;
if(fieldname3 == 95125) return 70;
if(fieldname3 == 94085) return 100;
if(fieldname3 == 94086) return 100;
})()

Best regards.

This topic has been closed to new replies.