Grouped radio buttons - auto populate another radio button based on response

May 25, 2018

Copy link to clipboard

Copied

Hi

I have searched the forums but can't find the answer to my question so I'm hoping someone on here can help.

I have a form in Adobe XI with a number of grouped radio buttons, if a user selects N/A on Section 1.1 I want all the subsequent questions in section 1.1 to auto populate the N/A radio button but if Yes or No is selected they should be able to select a radio button on the other questions.  Ideally, if N/A is selected they should also see a message telling them to go to the next question.

My form will look something like this

Section 1.1 - If N/A is selected all other questions in the group will all populate with N/A and a message will appear telling the user to go the next Section.  Alternatively if Yes or No is selected the user should select a response to the other questions.

Can this be done? I'd appreciate help on this one, I'm still a novice but have picked up some really useful information on this forum.

Ellen

Thank you Malcolm, I appreciate your assistance.  It's a long document so I've just taken one page out with all the code, see link below.

https://www.dropbox.com/s/2wws59itxg8stqb/Test%20Version.pdf?dl=0

Before uploading, I took the code out of the yes, no and NA fields just leaving the top level in but that's made no difference.

Ellen

TOPICS
Acrobat SDK and JavaScript, Windows

Views

441

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Grouped radio buttons - auto populate another radio button based on response

May 25, 2018

Copy link to clipboard

Copied

Hi

I have searched the forums but can't find the answer to my question so I'm hoping someone on here can help.

I have a form in Adobe XI with a number of grouped radio buttons, if a user selects N/A on Section 1.1 I want all the subsequent questions in section 1.1 to auto populate the N/A radio button but if Yes or No is selected they should be able to select a radio button on the other questions.  Ideally, if N/A is selected they should also see a message telling them to go to the next question.

My form will look something like this

Section 1.1 - If N/A is selected all other questions in the group will all populate with N/A and a message will appear telling the user to go the next Section.  Alternatively if Yes or No is selected the user should select a response to the other questions.

Can this be done? I'd appreciate help on this one, I'm still a novice but have picked up some really useful information on this forum.

Ellen

Thank you Malcolm, I appreciate your assistance.  It's a long document so I've just taken one page out with all the code, see link below.

https://www.dropbox.com/s/2wws59itxg8stqb/Test%20Version.pdf?dl=0

Before uploading, I took the code out of the yes, no and NA fields just leaving the top level in but that's made no difference.

Ellen

TOPICS
Acrobat SDK and JavaScript, Windows

Views

442

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 25, 2018 0
May 25, 2018

Copy link to clipboard

Copied

HI,

You could create 2 functions, probably best to add them at the document level, they would need to be something like this.

[ Code slightly more verbose than it probably needs to be for clarity ]

function disableRadioButtons ( controlButton, controlledButtons)

{

    var controlBut = this.getField ( controlButton);

    if ( controlBut.value == "Choice3")

    {

        for ( var i = 0; i < controlledButtons.length; i++)

        {

            var controlledBut = this.getField ( controlledButtons);

            controlledBut.value = "Choice3";

            controlledBut.readonly = true;

        }

    }

}

function enableRadioButtons ( controlButton, controlledButtons)

{

    var controlBut = this.getField ( controlButton);

    if ( controlBut.value != "Choice3")

    {

        for ( var i = 0; i < controlledButtons.length; i++)

        {

            var controlledBut = this.getField ( controlledButtons);

            if ( controlledBut.value == "Choice3")

            {

                // only if the NA option is selected do we unselect it.

                controlledBut.value = "";

            }

            controlledBut.readonly = false;

        }

    }

}

Then from the "Mouse Up" event if the non-NA buttons, call this

enableRadioButtons ( "Group1", ["Group2", "Group3", "Group4"]);

from the NA buttons call this.

disableRadioButtons ( "Group1", ["Group2", "Group3", "Group4"]);

Each function takes 2 parameters, the first is the NA button to control the logic, the second is an array of all the names of the groups that you want to be controlled.

Hope this helps

Malcolm

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 25, 2018 2
May 29, 2018

Copy link to clipboard

Copied

That's brilliant, thanks for your help

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 29, 2018 0
May 29, 2018

Copy link to clipboard

Copied

That all works really well, there is one slight problem though.  If the user changes their mind after selecting NA and wants to select Yes or No instead, the subsequent responses are still locked, is there a way around this?

Thaks

Ellen

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 29, 2018 0
May 29, 2018

Copy link to clipboard

Copied

Sorry, user error on my part , I re-read your instructions and moved some of the code into the correct fields!.

Once again, thank you.  It does exactly what I wanted it to do.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 29, 2018 0
Jun 08, 2018

Copy link to clipboard

Copied

Hello, me again

I've built my form but now found another issue.  When the user selections N/A in the subject area all N/A field in the selection auto populate and the remaining control buttons are disabled. if they select Yes the other control buttons are enabled and the user has a choice of Yes, No or N/A.  That all works well but in testing I've noticed if a user selects Yes in the subject area and then for example selects N/A to q2 and No to q3 the NA disappears when the response to q3 is is selected.  This video shows what's happening.

  https://www.dropbox.com/s/ql2z6e8qns3zleb/pdf%20form%20issue.mp4?dl=0

I've got the following Javascript:

Document level Script:

Disable Radio Buttons:

function disableRadioButtons ( controlButton, controlledButtons)

{

    var controlBut = this.getField ( controlButton);

    if ( controlBut.value == "NA")

    {

        for ( var i = 0; i < controlledButtons.length; i++)

        {

            var controlledBut = this.getField ( controlledButtons);

            controlledBut.value = "NA";

            controlledBut.readonly = true;

        }

    }

}

Enable Radio Buttons:

function enableRadioButtons ( controlButton, controlledButtons)

{

    var controlBut = this.getField ( controlButton);

    if ( controlBut.value == "NA")

    {

        for ( var i = 0; i < controlledButtons.length; i++)

        {

            var controlledBut = this.getField ( controlledButtons);

            controlledBut.value = "NA";

            controlledBut.readonly = true;

        }

    }

}

then

for the Yes and No responses Javascript on Radio Properties Action set to run on mouse up:

enableRadioButtons ( " GenPremInspections ", ["GenPremisesInspectionsUndertaken ", " GenPremisesDefectsActioned",

" GenPremInspectionsRecorded"]);

and for the NA responses - Javascript on Radio Properties Action set to run on mouse up:

enableRadioButtons ( " GenPremInspections ", ["GenPremisesInspectionsUndertaken ", " GenPremisesDefectsActioned",

" GenPremInspectionsRecorded"]);

I'm at a loss as to what's causing the issue and would welcome any help from the experts.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2018 0
Jun 08, 2018

Copy link to clipboard

Copied

Hi,

Just a thought, do you have the code on all 'Yes' and 'No' answers of just the "GENERAL PURPOSE INSPECTIONS" question? because it only needs to be at the top level to work as you described.

If not can you upload the file so that I can take a look at the code?

Regards

Malcolm

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2018 1
Jun 08, 2018

Copy link to clipboard

Copied

Thank you Malcolm, I appreciate your assistance.  It's a long document so I've just taken one page out with all the code, see link below.

https://www.dropbox.com/s/2wws59itxg8stqb/Test%20Version.pdf?dl=0

Before uploading, I took the code out of the yes, no and NA fields just leaving the top level in but that's made no difference.

Ellen

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2018 0
Jun 08, 2018

Copy link to clipboard

Copied

HI,

I would like to check the functionality you want to make sure I am understanding the result you need correctly.

In the form you have control questions and questions that are controlled.

CONTROL QUESTION - GENERAL PREMISE INSPECTIONS

This has the option of 'Yes' and 'N/A'.

If you select 'Yes' all questions of that section should be enabled.

If you select 'N/A' all question of that section should be disabled and controlled questions should be set to 'N/A'.

There is no 'No' Option.

CONTROLLED QUESTION - Are these inspections recorded and help on site?

This has the option of 'Yes', 'No', and 'N/A'

If you select 'Yes' nothing happens to any other field

If you select 'N/A' nothing happens

If you select 'No' nothing should happen - IS THAT CORRECT?

If the above is correct, then you need to remove the code from all the 'No' check boxes as it is not needed. The control question is the only one that requires the code to be applied.

If I have a mis-understanding, please respond with corrections and I will re-evaluate my answer.

Hope this helps

Malcolm

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2018 1
Jun 08, 2018

Copy link to clipboard

Copied

You've summed that up perfectly.

I thought I'd deleted the code from the No box but obviously hadn't.  Just tested it now with the code removed and it works as it should.  Thank you for taking the time to help.  I'll go and fix the other codes now ....

Ellen

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2018 0
EllenBCC LATEST
Oct 24, 2018

Copy link to clipboard

Copied

Hello

I'm hoping you can help me expand this javascript.

I've got an additional radio button on the control questions so I now have Yes, No, NA. How do I amend the script to include the No?  I've tried editing it but it doesn't work.

In addition, is it possible to have the controlled fields set to off rather than No or NA?

Thanks

Ellen

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 24, 2018 0