Java script for radio button values
Copy link to clipboard
Copied
Hi, I am creating a questionnaire using radio buttons, but I can't seem to get the script to work (the script below works perfectly for a checkbox button), the client wants to change the checklist to a radio button, I tried changing the script below from "checklist" to "radiobutton"but this didn't seem to work. In the pdf I have made all the field names etc exactly the same except it is now a radio button not a check box. Is it possible to get some help with the script below? Thank you.
{
var temp = 0;
for(var i = 0; i < this.numFields; i++)
{
var name = this.getNthFieldName(i);
var field = this.getField(name);
if (field.type == "checklist" && field.value != "Off")
{
temp += field.value;
}
}
this.getField("Total Score").value = temp;
var f = this.getField("Risk");
if (temp>=5 && temp <=24){
var g = this.getField(f.name+".0");
g.defaultIsChecked(0,true);
}
if (temp>=25 && temp <=39){
var g = this.getField(f.name+".1");
g.defaultIsChecked(0,true);
}
if (temp>=40 && temp <=54){
var g = this.getField(f.name+".2");
g.defaultIsChecked(0,true);
}
if (temp>=55 && temp <=64){
var g = this.getField(f.name+".3");
g.defaultIsChecked(0,true);
}
if (temp>=65 && temp <=75){
var g = this.getField(f.name+".4");
g.defaultIsChecked(0,true);
}
this.resetForm(["Risk"]);
}
Copy link to clipboard
Copied
The script above should not work at all, because there's no such field type as "checklist".
There's "checkbox" and there's "radiobutton"...
Copy link to clipboard
Copied
Hi,
I have worked it out thanks. It was "radiobutton". But also needed to add script into the area below:
Open you pdf file, get into the "Prepare Form", right click on the "total Score" text field, open the "Properties...", then like this picture,click the "Edit...", and input the script below.
if ( !event.willCommit && (event.change != "") )
{
var temp = event.change;
var f = this.getField("Risk");
//app.alert(g.name);
if (temp>=5 && temp <=24){
var g = this.getField(f.name+".0");
g.defaultIsChecked(0,true);
}
if (temp>=25 && temp <=39){
var g = this.getField(f.name+".1");
g.defaultIsChecked(0,true);
}
if (temp>=40 && temp <=54){
var g = this.getField(f.name+".2");
g.defaultIsChecked(0,true);
}
if (temp>=55 && temp <=64){
var g = this.getField(f.name+".3");
g.defaultIsChecked(0,true);
}
if (temp>=65 && temp <=75){
var g = this.getField(f.name+".4");
g.defaultIsChecked(0,true);
}
this.resetForm(["Risk"]);
}

