Skip to main content
Participant
October 15, 2025
Question

Help with JavaScript code for IF with a price range

  • October 15, 2025
  • 1 reply
  • 78 views

Looking to have a form that can populate when I enter one rate. I need a javascript that seems relativley easy. 

When I enter a rate in "Box A" I would like "Box B" to formulate, however I would like a price range to be added. 

Example:

"Box A"- (Price for snow removal) Rate can be anywhere from $40-50 to calculate "Box B" (salting rate) which would be $30 for the range of $40-50.00 

 

Any help is appreciated!!!  

    1 reply

    Karl Heinz  Kremer
    Community Expert
    Community Expert
    October 22, 2025

    Are there any ohter price ranges that you would apply different "salting rates" to? What if the Box A is set to 0? What if it's set to $10? What if it's set to $60? 

     

    You might be able to make the necessary modifications yourself - try this as the custom calculation script for Box B:

     

    // get the current value from "BoxA"
    
    var boxA = this.getField("BoxA").value;
    var thisValue = 0;
    if (boxA == "" || boxA == 0) {
        thisValue = 0;
    }
    else if (boxA > 0 && boxA < 40) {
        thisValue = 5;
    }
    else if (boxA >= 40 && boxA <= 50) {
        thisValue = 30;
    }
    else {
        thisValue = 50;
    }
    event.value = thisValue;