Expand my Community achievements bar.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!
SOLVED

Want to fill in all fields in a section based on yes or no answer to a beginning question

Avatar

Level 7

I have a multi-page, multi-section form I'm creating. Some of the sections begin with a yes or no question, If the answer is no, then all the fields can be filled in as N/A which has a value of zero. I'm using drop-down list in the fields and assigning values to the yes, no, N/A answers.

Is there a way to set the values to all the fields in a section to N/A if the answer to the beginning question is No?

Thanks,

MDawn

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Margaret,

I didn't realise the yes/no questions were in a radio button group.

In this case I would put the script in the click event and instead of using xfa.event.newText (which relates to the change event), you would use the 'this.rawValue' to test against the users response.

So the click event would look like this:

switch (this.rawValue)

{

     case "Yes": // or whatever you have bound a yes answer to

     textfield1.rawValue = "";

     textfield2.rawValue = "";

     case "No":

     textfield1.rawValue = "N/A";

     textfield2.rawValue = "N/A";

}

You can place this script in the click event of the radio button group, which will cover both radio buttons in the group. Remember to have the form set to automatically save script changes (File > Form Properties > Defaults).

Yes, 'textfield1' is an example of an object in the subform that you want to assign as N/A. If the user answers No, then N/A will appear in the value portion of the object.

Hope that helps,

Niall

View solution in original post

12 Replies

Avatar

Level 10

Hi Margaret,

Yes this is possible.

In the yes/no object put similar javascript in the change event:

switch (xfa.event.newText)

{

     case "Yes":

     textfield1.rawValue = "";

     textfield2.rawValue = "";

     case "No":

     textfield1.rawValue = "N/A";

     textfield2.rawValue = "N/A";

}

Note that this solution will clear any data that  the user has previously inputted into the fields. This can be frustrating for the user.

Another solution would be to show/hide the subform, depending on the yes/no answer. This would use the .presence = "visible"; // "hidden";

Good luck,

Niall

Avatar

Level 7

Thanks.

Margaret Dawn

Supervisor - Documentation

W: 630-850-1065

Avatar

Level 7

When I select the radiobutton list and then the change event, the list and two fields are listed in the Script Editor. Where does the script go?

Am I understanding it correctly, that then I replace "textfield1" with the actual name of each field. Will the N/A actually be displayed in the field for the end user to see?

Thanks,

Margaret Dawn

Supervisor - Documentation

W: 630-850-1065

Avatar

Correct answer by
Level 10

Hi Margaret,

I didn't realise the yes/no questions were in a radio button group.

In this case I would put the script in the click event and instead of using xfa.event.newText (which relates to the change event), you would use the 'this.rawValue' to test against the users response.

So the click event would look like this:

switch (this.rawValue)

{

     case "Yes": // or whatever you have bound a yes answer to

     textfield1.rawValue = "";

     textfield2.rawValue = "";

     case "No":

     textfield1.rawValue = "N/A";

     textfield2.rawValue = "N/A";

}

You can place this script in the click event of the radio button group, which will cover both radio buttons in the group. Remember to have the form set to automatically save script changes (File > Form Properties > Defaults).

Yes, 'textfield1' is an example of an object in the subform that you want to assign as N/A. If the user answers No, then N/A will appear in the value portion of the object.

Hope that helps,

Niall

Avatar

Level 7

Thank you. This helps.

Margaret Dawn

Supervisor - Documentation

W: 630-850-1065

Avatar

Level 7

Hi, Niall,

When you say..." then N/A will appear in the value portion of the object." What does that mean? I'm not sure what or where the value portion of the object is. Since I'm calculating the score of each question, I'll need to have that value.

Thanks,

Margaret Dawn

Supervisor - Documentation

W: 630-850-1065

Avatar

Level 10

Hi Margaret,

Sorry, in the example above I was writing the script directly into the post and forget to include the break; statement.

The script in the click event is:

switch (this.rawValue)

{

     case '1': // Yes is bound as 1

     firstName.rawValue = "";

     lastName.rawValue = "";

     company.rawValue = "";

    break;

     case '0':

     firstName.rawValue = "N/A";

     lastName.rawValue = "N/A";

     company.rawValue = "N/A";

     break;

}

When I said value portion of the object, I meant the area that is available for the user to type information into. The other portion of the object would be the caption.
Hope that helps,
Niall

Avatar

Level 7

I got it to work! Thanks for your script help.

Margaret Dawn

Supervisor - Documentation

W: 630-850-1065

Avatar

Level 7

I got this to work perfectly on one page. Now on the second page, I'm getting this error:

form1.page6.Table1.Row10[0] has no properties

26:XFA:form1[0]:page6[0]:mailOrderButtonList[0]:click

I can't figure out what the first line is referring to. I was able to troubleshoot getting the first page working, but this has me stumped.

Thanks,

Margaret Dawn

Supervisor - Documentation

W: 630-850-1065

Avatar

Level 10

Hi Margaret,

From the debugging message it is saying that the radio button group "mailOrderButtonList" on "page6" has an error on line "26" of the click event.

"Row10[0]" does not have any properties.

If you are trying to change the .rawValue of an object within a repeating row, then you will need to loop through each of the rows one at a time and set the object in each row. Reading the error message I am guessing that this is the problem.

There is an example here show script looping through and looking at the .rawValue of an object in a repeating row. It would be the same approach, just setting the .rawValue instead.

Niall

Avatar

Level 10

Avatar

Level 7

I had the values set wrong on the Yes and No of the radio buttons on the Binding tab. The script was referring 1 and 0 and the values on the Binding tab were 1 and 2. Once I fixed that, it worked.

Margaret Dawn

Supervisor - Documentation

W: 630-850-1065