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

radio button

salkins
Registered: May 19 2008
Posts: 6

I have a group of six radio buttons of which I need one to automatically fill in based upon a value in a numeric field.

For example if numericfield8 = or is greater than 110 then we'll need a radio button from the group of six to be selected automatically so that the person filling out the form doesn't need to.

Help!!!

My Product Information:
LiveCycle Designer, Windows
StevenD
Registered: Oct 6 2006
Posts: 368
I tried this JavaScript that I put in the Validate event of the radio button list. To make it easy to select that list I selected it in the Hierarchy.

var myVal = NumericField1.rawValue;
if(myVal >= 110)
{
RadioButtonList.rawValue = "6";
}
else
{
RadioButtonList.rawValue = "0";
}

StevenD

StevenD

StevenD
Registered: Oct 6 2006
Posts: 368
Incidentally I have been using a couple of references that contain some good scripting examples that have helped me out.

Adobe XML Form Object Model Reference. Go to the JavaScript Examples which is Appendix A. I got the method for the script from this document.

and

LiveCycle Designer Scripting Basics. Chapter 13 has some script examples of common scripting tasks. This is also found in the LiveCycle Designer Help. Go to the Contents tab > Scripting > Scripting Using LiveCycle Designer > Examples of common scripting tasks.You should be able to find these on the Adobe LiveCycle developer site. They are both PDFs.

StevenD

StevenD

salkins
Registered: May 19 2008
Posts: 6
Thanks for your help but its not working for me. I am really not familiar with this at all.
What is the "6" and the "0" in reference to? Do I need to assign names to each RadioButton in the list?
StevenD
Registered: Oct 6 2006
Posts: 368
The numbers refer to the particular radio button. For instance if you have a radio button list that has 6 radio button in it the number 6 means radio button number 6 in the list. The 0 means no radio buttons.

The references in the example script to elements in the form are default names of field elements such as NumericField1 and RadioButtonList. You may have given them other names (I usually do this) which you will need to replace the default names with. I haven't been naming the individual buttons in a list or group but do rename the button list so it makes sense to me. But technically you don't need to assign names.

What you would do is select the radio button list and add the script to the validate event. When I was first working with LC Designer I would some times accidentally grab a single radio button in list instead of the list or group of buttons. Now I use the Hierarchy to select objects on the page.

StevenD

salkins
Registered: May 19 2008
Posts: 6
Thank you so much for helping. I am now able to see the radio button fill in automatically so I guess I am getting closer but its not filling based on the value of the NumericField. Do I need to write the code separately for each radio button or do I do it all as I did below?

This is the field the radiobuttons are based on: We are a financial firm and its a suitability questionnaire. The radio button should automatically fill in the model (ie: Growth) based on the total.

NumerField8 _________________ (total)

The RadioButtonList is as follows (the 0 is the radio button).

0 110-125 Aggressive Growth
0 94-109 Growth
0 78-93 Balanced Growth
0 62-77 Balanced
0 46-61 Balanced Income
0 30-45 Capital Preservation

This is the code I have written for radio button 5 and 6:

var myVal=NumericField8.rawValue; if(myVal>=110) {RadioButtonList.rawValue="6";} else{RadioButtonList.rawValue="0";} if(myVal=94-109) {RadioButtonList.rawValue="5";} else{RadioButtonList.rawValue="0";}Any further assistance would be greatly appreciated!!!
Sandy
StevenD
Registered: Oct 6 2006
Posts: 368
There are some errors in the script in the syntax. And part of it has to do with ranges in other words if the value of the field is equal to or between 94 and 109 then check the appropriate box. I have seen this before but can't remember where I saw it so it may take a while to get it figured out which is good for me as I am learning something.

If there is anyone else reading this thread who is faster at scripting than I am maybe they can jump in.

StevenD

StevenD
Registered: Oct 6 2006
Posts: 368
Okay I think this may be it.

var myVal = NumericField8.rawValue;
if(myVal>=110)
{
RadioButtonList.rawValue="6";
}
else
if(myVal >= 94 && myVal <= 109)
{
RadioButtonList.rawValue="5";
}
else
{
RadioButtonList.rawValue="0";
}

I tried this and it works. One of the things I had trouble with when I first started out with JavaScript was keeping the "=" and the "==" operator straight. The single "=" is the assignment operator which for example can be used to assign a value to a variable like we did in the first line of the script. The "==" is a comparison operator which is used to compare to values. Now in the case where we want to compare the value of the numeric text field with a range of numbers like the 94 to 109 I used "&&" which is a logical operator. Essentially it says if the value is between 94 and 109 then do something.I was hoping to get a simpler solution by using a switch statement instead of an if statement but I can't get it to work.

Give this a try and see what happens. I hope it works for you.

StevenD

StevenD
Registered: Oct 6 2006
Posts: 368
Oops I think I goofed. Try this one instead.

var myVal = NumericField8.rawValue;

if(myVal >= 94 && myVal <= 109)
{
RadioButtonList.rawValue="5";
}
else
if(myVal == 110) //You could use >= instead of == if you didn't want to limit it to 110.
{
RadioButtonList.rawValue="6";
}
else
{
RadioButtonList.rawValue="0";
}

I think the order may work better.

StevenD