0

I have a 2-d array of the form:

Array ( [0] => Array ( [A] => aaa [B] => bbb [C] => ccc [D] => ddd ) [1] => Array ( [A] => aaaa=1 [B] => bbb1 [C] => ccc1 [D] => ddd1 ) ... )

and I have a form like:

A: choose A
B: choose B
C: choose C

where the contents of the select menu's A, B and C are populated based on the previous select menu option chosen.

Like if the values for A are android, ios, windows, the values for B are htc, lumia, iphone, samsung and the values of C are htc one, htc first, lumia 920, iphone4, iphone5, galaxy 4.

Does anyone know how I can do this?

Thanks!

Kitty1911
  • 661
  • 1
  • 8
  • 15
  • Do you mean you want to create a *drill-down* form? – hakre Apr 19 '13 at 20:23
  • yes. Can you point me in the right direction? – Kitty1911 Apr 20 '13 at 02:23
  • 1
    You need to have data that can be drilled down. It could be often visualized like a tree and then each input is a decision how to traverse this tree. This is best done with a pencil and a sheet of paper first. Visualize what you want to do and illustrate the interactivity and what it does with the data. – hakre Apr 20 '13 at 07:14
  • This could be accomplished with straight HTML and PHP, though the page would need to refresh after each selection. I assume you are wanting it to be more dynamic and without page refreshes. In that case you will want to add JavaScript/AJAX into the mix. You could indeed pull all associated data immediately on page load, and then just manipulate that date with JS as needed. Or you could use AJAX to make a new query to the server after each selection. It all depends on your needs. I agree with @hakre, map out exactly what you want. Draw a picture of your intended results, then building it. – SunSparc Jun 18 '13 at 16:07

1 Answers1

0

This has been my problem too. Most of the online tutorials propose a method for chained selects with data fetched directly from the DB and not with data already available in arrays.

You can start with this online tutorial, which I have found to be quite useful, at least for me: http://tutorialzine.com/2011/11/chained-ajax-selects-jquery/

In the section "ajax.php / 2" is where you create the select-boxes based on the data from your array.

I didn't find it quite ready-to-copy-paste and it needed a bit of tweaking to match my requirements, but, in the end, it worked.

Orestes Echo
  • 53
  • 1
  • 10