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

Converting a radio button's value to a numeral

krishunt
Registered: Jan 21 2010
Posts: 2

I have a series of questions on a form, each of which has five radio buttons to designate the answer, ranging from 1 (poor) to 5 (excellent). I have the export value of each button set to just the numeral, which I assume Acrobat treats as a text string, and not an actual number. What I want to do is calculate and display an average of all the values. How do I convert each radio button's text string output to an integer than can be manipulated mathematically?

My Product Information:
Acrobat Pro 9.2, Macintosh
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In the calculation script you need to cast the radio button field's value in to a number

For example:
var cExport = this.getField("MyRadio").value;var nExport = 0;if(!isNaN(cExport))nExport = Number(cExport);

In the Radio group does not have a selection then the value will be "Off". So if there is a chance that there will not be a selection the code needs to test the value before making a conversion. The code above insures a default value of zero. If the selection is garunteed to be something then the test is unnecessary.

Number conversions can also be done by forcing a numeracal context:
For example:
nExport = cExport*1;

However, I like the explict cast better.


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script