There is the following function that displays a form in which there are 2 fields with a list of data from a table with a hierarchy. How do I make these 2 combo boxes dependent so that when you select a value in the first field, the corresponding fields are displayed in the second field.
function input_recipe() { // Создаём выпадающий список 1 $dropDown = '<select name="cat_name">'; $query = mysql_query('select * from category where level = 1'); if (mysql_num_rows($query)) { while ($cat = mysql_fetch_array($query)) { $dropDown .= sprintf( '<option value="%s">%s</option>', $cat["id_category"], $cat["name"] ); } } $dropDown .= '</select>'; // Создаём выпадающий список 2 $dropDown2 = '<select name="cat2_name">'; $query = mysql_query('select * from category where level = 2'); if (mysql_num_rows($query)) { while ($cat = mysql_fetch_array($query)) { $dropDown2 .= sprintf( '<option value="%s">%s</option>', $cat["id_category"], $cat["name"] ); } } $dropDown2 .= '</select>'; // Вставляем их в форму. $txt = sprintf("<form method='post'><table> <tr> <td style='text-align: center; font-weight: bold;'>Категория</td> <td style='text-align: center; font-weight: bold;'>Категория</td> <td style='text-align: center; font-weight: bold;'>Название</td> <td style='text-align: center; font-weight: bold;'>Описание</td> </tr> <tr> <td>%s</td><td>%s</td> <td><input type='text' name='recipe_name' id='recipe_name'></td> <td><input type='text' name='recipe_description' id='recipe_description'></td> </tr> <tr> <td colspan='4' style='text-align: center'><input type='submit' value='Добавить запись'></td> </tr> </table></form>", $dropDown, $dropDown2 ); return $txt; }