Copy link to clipboard
Copied
Hi all,
I have a form field (“RB_Inc_9”) that I want to auto-calculate based on what radio button is selected. Please see the below screenshot for reference:
Here’s what I want to see:
I’ve done some research but still can’t figure out exactly how to run if/then statements in Javascipt.
Thanks!
Copy link to clipboard
Copied
Use this:
var overhead = this.getField("RB_Inc_9").valueAsString;
if (overhead=="Salary") {
// insert code here
} else if (overhead=="Direct Costs") {
// insert code here
}
Copy link to clipboard
Copied
Use this:
var overhead = this.getField("RB_Inc_9").valueAsString;
if (overhead=="Salary") {
// insert code here
} else if (overhead=="Direct Costs") {
// insert code here
}
Copy link to clipboard
Copied
Hi, thanks very much for the input! I tried the code but it didn't work - see below (the IDs of the radio buttons are accurate according to my file; e.g. the Salary radio button = "OH_Sal", and the Direct Cost radio button = "OH_DC"): Let me know if you have any suggestions!
var OH_Calc = this.getField("RB_Inc_9").valueAsString;
if (OH_Calc=="OH_Sal") {
// event.value = this.getField("OH").value * this.getField("RB_Inc_1").value + this.getField("OH").value * this.getField("RB_Inc_2").value
} else if (OH_Calc=="OH_DC") {
// event.value = this.getField("OH").value * this.getField("RB_Inc_1").value + this.getField("OH").value * this.getField("RB_Inc_2").value + this.getField("OH").value * this.getField("RB_Inc_3").value + this.getField("OH").value * this.getField("RB_Inc_4").value + this.getField("OH").value * this.getField("RB_Inc_5").value + this.getField("OH").value * this.getField("RB_Inc_6").value + this.getField("OH").value * this.getField("RB_Inc_7").value + this.getField("OH").value * this.getField("RB_Inc_8").value
}
Copy link to clipboard
Copied
Remove the "//" part... That's how you create a comment.
Copy link to clipboard
Copied
Still nothing! Not sure what I'm doing wrong...
var OH_Calc = this.getField("RB_Inc_9").valueAsString;
if (OH_Calc=="OH_Sal") {
event.value = this.getField("OH").value * this.getField("RB_Inc_1").value + this.getField("OH").value * this.getField("RB_Inc_2").value
} else if (OH_Calc=="OH_DC") {
event.value = this.getField("OH").value * this.getField("RB_Inc_1").value + this.getField("OH").value * this.getField("RB_Inc_2").value + this.getField("OH").value * this.getField("RB_Inc_3").value + this.getField("OH").value * this.getField("RB_Inc_4").value + this.getField("OH").value * this.getField("RB_Inc_5").value + this.getField("OH").value * this.getField("RB_Inc_6").value + this.getField("OH").value * this.getField("RB_Inc_7").value + this.getField("OH").value * this.getField("RB_Inc_8").value
}
Copy link to clipboard
Copied
Check the JS Console (Ctrl+J) for error messages.
Copy link to clipboard
Copied
Good morning
I have a group of 3 radio buttons, I would need to select one of them to return a result in a text box.
The group is called group 1 and each button 1.1, 1.2, 1.3
Can you help me.
Copy link to clipboard
Copied
You can use this code as the custom calculation script of your text field:
var v = this.getField("group 1").valueAsString;
event.value = (v=="Off") ? "" : v;
Copy link to clipboard
Copied
Thanks a lot