Skip to main content
Participant
June 17, 2020
Question

How to set form field to auto fill based on another field

  • June 17, 2020
  • 1 reply
  • 403 views
  1. I have fields that are autopopulated based on radio button selection of another field (point values 0-5 or fewer options for some). 
  2. I then have a field (named TotalPoints) that sums these values, minimum total points=1, maximum=23 (integers)
  3. My third field (named Accreditation Fee) needs to display a price (or simply a number) based on the total points.
  4. If the points > than 15, I created a field (named ContactOCPD) with the folloing JavaScript (located in custom caluculation script) that works perfectly:

    var t = this.getField("TotalPoints").value;

    if (t > 15) {event.value = "Contact OCPD";}

    else {event.value = "";}

  5. I created another field (which will sit on top of field from 4) with the folloing JavaScript. Nothing happens:
    var t = this.getField("TotalPoints").value;
    if (t = 0) {event.value = 0;}
    else if (t > 0 && t < 4) {event.value = 500;}
    else if (t > 3 && t < 7) {event.value = 1000;}
    else if (t > 6 && t < 9) {event.value = 2000;}
    else if (t > 8 && t < 12) {event.value = 3000;}
    else if (t > 11 && t < 14) {event.value = 4000;}
    else if (t > 13 && t <16) {event.value = 5000;}
    else if (t>15) {event.value = "";}
    What am I doing wrong? I have tried playing with the brackets and quotations. Nothing shows up in the field, no matter what number is in the TotalPoints field. Thank you!
This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
June 17, 2020

5. replace

if (t = 0) {event.value = 0;}

by

if (t == 0) {event.value = 0;}