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

?? Require field based on Radio Button selection

cddyson
Registered: Jan 21 2009
Posts: 3
Answered

Hi All,
I am new to Javascript and am trying to make a field required based on a radio button selection. Can someone point me in the right direction? I have searched through the posting but don't find anything close enough that I can understand and therefore copy. Thanks much!!

My Product Information:
LiveCycle Designer, Windows
nixopax
Registered: Feb 6 2009
Posts: 105
var f = this.getField("myField");f.required = true;

This is the basic way to make a field required. It checks for field values that are null and generate a warning and cancel form submission. This requires form rights for it to work in Reader.

I prefer a bit more control over field validation, so I write scripts specific to the type of information required.

Here's a great starting point:
http://www.adobe.com/devnet/acrobat/pdfs/js_api_reference.pdf
cddyson
Registered: Jan 21 2009
Posts: 3
Does the code go on the radio button that will be clicked or on the required field? My radio button is:RadBtnList.ExistNumb. The required field is:ExistingFormNumber.

Thanks.
nixopax
Registered: Feb 6 2009
Posts: 105
Well, the logic itself is up to you.

Let's say your form looks like this:

O - Radio1
O - Radio2
O - Radio3

[____] - Text1
[____] - Text2
[____] - Text3

What you could do is each radio button will have a Mouse up action that sets each text field to be required. But the issue that you run into is if they change their selection, then more than one field will be required. So you need to ensure that the other fields are unset from being required.

For our example:

Set the action for your radio buttons to be:
required(1);
change the 1 to 2 or 3 for radio buttons radio2 and radio3 respectively.

Then in your document level javascript:
function required(nField){switch(nField){case 1:this.getField("Text1").required = true;this.getField("Text2").required = false;this.getField("Text3").required = false;break case 2:this.getField("Text1").required = false;this.getField("Text2").required = true;this.getField("Text3").required = false;break case 3:this.getField("Text1").required = false;this.getField("Text2").required = false;this.getField("Text3").required = true;break}}

You could go a step further and even change the non required text fields to readonly and hidden.
JetFan
Registered: Nov 9 2009
Posts: 1
I Forgive me but I am very new to this type of programming. I have a very similar question as cddyson.

I have created a form in Acrobat 9 which contains 4 radio buttons. Depending on the radio button selected the user is needs to enter specific information in a text field(s).

The format of the form is as follows:

Radio button1 – please provide this information in the following text field
Radio button2 – please provide this information in the following text field
Radio button3 – please provide this information in the following text field
Radio button4 – please provide this information in the following text field
(in this case, 3 pieces of information needs to be provided)

I would like to set the form up so that if the user selects radio button1 they can only enter information in the text field to the right of that button.

Should I follow the same steps that were given to cddyson? How do I set the action for the radio buttons to be required? Do I select the Options tab from the Properties menu?

Thank you.