Skip to content
Advertisement

Distributing sequential array items as mixed

I have an ordered list from 1 to 15. I put these list items in a form and assigned a checkbox to each. An user can choose whatever he wishes from the items in this form.

When the user fills in and sends the form, I want to separate this list under certain headings.

For example:

JavaScript

According to the results you choose:

Category A
Questions in this category: 1 – 3 – 4 – 10
You selected: 3 – 4 – 10

Category B
Questions in this category: 2 – 8 – 11 – 14 – 15
You selected: 2 – 8 – 11

Category C
Questions in this category: 5 – 6 – 7 – 9 – 12 – 13
You selected: 5 – 7 – 12 – 13

Can you give me an idea of how I can do this?

Advertisement

Answer

I found the answer to the question I asked by searching. For those who need help with this, I add it here.

First, make the options of each category into an array.

JavaScript

Then insert these arrays into the foreach loop and check if the selected options are in this array. An example for category A:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement