• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Driven radio buttons

New Here ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

i have a form that averages radio button values to determine overall grade (numbered 16-0.) Is it possible to have the overall mark radio buttons driven by the total? so when the average is calculated, it activates the relevant radio?

thanksPicture1.jpg

TOPICS
PDF forms

Views

688

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

It might be easier to start with calculating the average into a text box.

How are unchecked items to be accounted for?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

Yeah I have each of the individual radio bars averaging out to a text box, then I take the average of all the numbers to the main field.

The radio buttons are set up so one is always selected. I’m starting to think the only way is to replicate the look of radio buttons and get an ‘x’ to appear in the relevant spot

Max Pownall

Senior Lecturer - Product Design

NTU

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

You should be able to round or truncate that value to an integer value and then set the bottom row of radio buttons to that value when the bottom row has the export values set to the value of the column in which they appear. You should be able to use one of the Math objects methods of "floor", "round", or "ceil" to adjust the value of the calculation to the desired integer value. You may need to add some special code to account for the situation where all the radio buttons are in the "Off" position.

Note that the "Formatted" action sets only the displayed value of the field and not the actual value of the field. The actual value of your calculated average is 6.25. You can see this by changing the value of the "Decimal Places" to a value of 2 or larger. One could even use the format of "None".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 14, 2018 Jun 14, 2018

Copy link to clipboard

Copied

Great ok thanks. So I need to get the average to round to a whole number, and then set the bottom row to match that value? But how do I tell the radio buttons to reference the calc rather than determining the number themselves? in effect i want to do something similar to this -

Looking for help with javascript to autofill checkboxes based on a numeric value.

but with specific radio buttons.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2018 Jun 15, 2018

Copy link to clipboard

Copied

That could work if you appropriately change the values for the logical statements.

The big issue is how you are calculating the average. If one uses the "Field is the average of the following fields:" then you cannot apply the rounding or modification of the result. The same applies when using the "Simplified field notation". The only location one can add the rounding or switch selection is in the Custom JavaScript calculation". To perform the custom calculation one needs to access is field by the field's name.

The custom calculation script for the text field that displays the computed average the script could look like:

event.value= "";

var aRadioButtons = new Array("Group.0", "Group.1", "Group.2", "Group.3");

var aValues = new Array();

var oField;

var nAverage = "";

var nSum = 0;

// add radio button values to array of values;

for(var i = 0; i < aRadioButtons.length; i++) {

     oField = this.getField(aRadioButtons);

     if(oField != null){

          aValues.push(oField.value);

     } // end field object not null;

} // end loop of field names;

// filter out "Off" values;

function NotOff(element){

return element != "Off";

} // end filter function;

aValues = aValues.filter(NotOff);

if(aValues.length > 0){

     // summ values in the array;

     for(var i = 0; i < aValues.length; i++){

     nSum += Number(aValues);

     } // end sum values in the arrray;

// compute the average;

nAverage = nSum / aValues.length;

} // end number of elements in the array not zero;

event.value = nAverage; // set the text field

// round value and set average radio button value;

this.getField("AvgRB").value = Math.round(nAverage);

You may need to change field names to match your form.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 18, 2018 Jun 18, 2018

Copy link to clipboard

Copied

LATEST

Ok so that's worked great to give me whole numbers for the average, does it matter that they are not rounding to whole numbers, but to 0.25/0.5 etc, if i want to drive check boxes/radios?

i just need the lower radios to adjust based on the averaged number, any idea? I couldn't work out the correct code for using check boxes.

thanks for your help so far!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines