DropDown Menu Affecting other DropDown Menu

How can I make something like that:
I will have 3 dropdown menus
First Dropdown menu will be: Class
Second Dropdown menu will be: Area

Third Dropdown menu will be: options that will change

3 Examples:

  1. if I choose on “Class” Dropdown menu the option “A”
    It will show on the the Third Drop down
    “A1”,“A2”,“A3”
  2. if I choose on “Class” Dropdown menu the option “B”
    It will show on the the Third Dropdown
    “Y1”,“Y2”,“Y3”
  3. if I choose on “Class” Dropdown menu the option “A” and on “Area” dropdown menu the option “Center”
    It will show on the the Third Dropdown
    “X1”,“X2”,“X3”

And I need to get the categories from Database…

How can it be done?

one way is: Felgall Javascript - Dynamic Dropdown Boxes

Thanks!
Its working… althought I took me like a hour to make it work
and it looks really messy…

Is there a better way than that?
since im printing all the possible if/else if statements… and it looks kinda messy…