Rather than using PHP, it will be better if you use PHP to build javascript function to create arrays of items for each selectbox, i.e data_1=new Option('direction','');data_2=new Option('sex','');data_1_1('right',0); data_1_2=new Option('left',1);data_2_1=new Option('female',1);data_2_1=new Option('male',0), etc.
Then, another function to work with 'onChange' to handle selectbox1 change.