These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Export values in radio buttons

msmom1
Registered: Jul 24 2008
Posts: 3

I am creating a "quiz" and I understand the export values and how to total to get a "score" but I am having difficulty in one thing. if "a", "B", "c" & "d" are independently marked the score is 0 (I understand this part) but if c & D are marked the score is 1 ( not understood).

I am not sure on how to get this to work any suggestions?

Misty

My Product Information:
Acrobat Pro 8.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Are you creating this form in Acrobat or Designer? I don't understand how you've set up the form and the "score" calculation. Can you provide more details? If you've created a calculation script, can you post it here?

George
msmom1
Registered: Jul 24 2008
Posts: 3
I am using Acrobat 8.0 professional, I have used the Calculate tab in the properties of a text field. I am not using a script as I do not know much about java. I have uploaded a sample here: [url=http://www.msmom1.com/pdfsample.pdf]sample[/url]

Misty
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
That form has five items (A, B, C, D, and E). What should the score be if D and E are both selected, and any of A, B, or C are also selected?

George
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You need to use a custom JavaScript calculation to sum the fields. Then test to see if any of the wrong fields were also selected and if so force the sum to zero. And finally check to see if the test sum is 2.

So one could use:

// fields are named "Radio Button3.#" where # = 0 - n
console.show(); // some processing information
console.clear();

// get button fields as an array
var aButtons = this.getField("Radio Button3").getArray();

var fSum = 0; // sum of numberic values
// sum button fields
for(i = 0; i < aButtons.length; i++) {
console.println(i + ": " + aButtons[i].value);
if(!isNaN(aButtons[i].value)) fSum += aButtons[i].value;
}
console.println("fSum = " + fSum);

// if any button field is zero then the sum is zero
for(i = 0; i < aButtons.length; i++) {
if(!isNaN(aButtons[i].value) & aButtons[i].value == 0) fSum = 0;
}

// see if fSum is 2 then field value is 1 else field value 0
if(fSum == 2) event.value = 1;
else event.value = 0;One could also assign a power of 2^n for each n button and then check the reultant value to determine the score.

// fields are named "Radio Button3.#" where # = 0 - n
// export value for any buttion in 2^#

console.show(); // some processing information
console.clear();

// get button fields as an array
var aButtons = this.getField("Radio Button3").getArray();

var fSum = 0; // sum of numberic values
// sum button fields
for(i = 0; i < aButtons.length; i++) {
console.println(i + ": " + aButtons[i].value);
if(!isNaN(aButtons[i].value)) fSum += aButtons[i].value;
}
console.println("fSum = " + fSum);

// see if button 3 and 4 are checked
// button 3 value = 8 (2^3)
// button 4 value = 16 (2^4)
// total is 24
if(fSum == 24) event.value = 1;
else event.value = 0;

George Kaiser

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
With a little thoguht and a document level function, one could create a fucntion that could determine if and answer for a series of buttons for any question had the correct answer based on a string pattern for the correct answer. Like:

function CheckAnswer(sFieldName, sCorrectAnswer) {
// document level function to determine if check boxes or radio buttons
// in a quiz have the correct answer - supports multiple answers
// get the radio button group field object as an array

var aFields = this.getField(sFieldName).getArray();
var sAnswer = ''; // temp variable for button answer
var sAnswerString = ''; // temp variable for entire answer string

// loop through the fields and build the answered string
for(i = 0; i < aFields.length; i++) {
sAnswer = aFields[i].value.toString(); // get value of a single button
if(aFields[i].value == "Off") sAnswer = 'n'; // force "Off" value t
sAnswerString = sAnswerString + sAnswer; // add button answer to answer string;
} // end loop through the buttons

// return true for correct answer else return false
return sAnswerString == sCorrectAnswer;
} // end CheckAnswer
// end document level function


// custom calculation script for each questions answer box:
// assume the answer is not correct
event.value = 0;

// set parameters for checking
// check boxes or radio buttons to check
var sFN = 'Radio Button3';
// correct answer pattern to match
// n = should not be selected, 1 = correct selection
sCA = 'nnn11'; // answer string is 1 mo, 2 no, 3 no, 4 select, 5 select
// set to 1 if the answer string is correct using field name and answer pattern
if(CheckAnswer(sFN, sCA) == true) event.value = 1;

George Kaiser