Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Looping Through Form Validating Checkbox Options

Avatar

Avatar
Validate 1
Level 1
christophers795
Level 1

Like

1 like

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
christophers795
Level 1

Like

1 like

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
christophers795
Level 1

29-06-2015

We would like to add a validation through our form before other scripts get implemented. Here's the workflow:

  1. User goes through and provides answers to checkbox radio buttons (user can only selection one of 3 options)
  2. The user hits a button and there is a validation that the user answered all of the questions.
  3. If the user did not answer all the questions, the form displays the questions the users did not answer in one alert box (Lists the questions by number, preferably).

I found the following script on another website, and while it looks right, I assume that I don't know how to appropriately pull first all the objects in my document and then only pull the radio buttons for the check.

function validateForm()

{

    var ShowAlert = '';

    var AllFormElements = xfa.host.topmostSubform.getElementById("FormID").elements;

    for (i = 0; i < AllFormElements.length; i++)

    {

        if (AllFormElements[i].type == 'radio')

        {

            var ThisRadio = AllFormElements[i].name;

            var ThisChecked = 'No';

            var AllRadioOptions = document.getElementsByName(ThisRadio);

            for (x = 0; x < AllRadioOptions.length; x++)

            {

                 if (AllRadioOptions[x].checked && ThisChecked == 'No')

                 {

                     ThisChecked = 'Yes';

                     break;

                 }

            }  

            var AlreadySearched = ShowAlert.indexOf(ThisRadio);

            if (ThisChecked == 'No' && AlreadySearched == -1)

            {

            ShowAlert = ShowAlert + ThisRadio + ' radio button must be answered\n';

            }    

        }

    }

    if (ShowAlert != '')

    {

    alert(ShowAlert);

    return false;

    }

    else

    {

    return true;

    }

}

I'm not particularly attached to this scripting, so if you have a better way of completing this please feel free to let me know.

Thank you in advance for your assistance.

Accepted Solutions (0)

Answers (0)