Сделал зависимые поля со списком, но если разместить эти поля в форме, то второе поле со списком не заполняется. Вне формы всё работает. Как сделать чтобы второе поле со списком заполнялось в форме?
<div class="tb"><form><table>
<tr>
<th colspan="3" scope="col">Рецепт</th>
</tr>
<tr>
<td width="77" style="text-align: center; font-weight: bold;">Категория</td>
<td width="144" style="text-align: center; font-weight: bold;">Название</td>
<td width="209" style="text-align: center; font-weight: bold;">Описание</td>
</tr>
<tr>
<td>
<?php
require('connect.php');
echo '<select name="category" id="category" class="StyleSelectBox" onchange="javascript:category(this.value);return false;">';
if($_POST["category"]*1)
echo '<option value="0">- Категория -</option>';
else
echo '<option value="0">- Категория -</option>';
$query = mysqli_query($link,'select * from category where level=1');
if(mysqli_num_rows($query))
while($category = mysqli_fetch_array($query))
if($_POST["category"] == $category["id_category"])
echo '<option value="'.$category["id_category"].'" selected>'.$category["name"].'</option>';
else
echo '<option value="'.$category["id_category"].'">'.$category["name"].'</option>';
echo '</select>';
echo '<br/><select name="category_2" id="category_2" class="StyleSelectBox"></select>';
?>
</td>
<td><input type="text" name="textfield" id="textfield"></td>
<td><input type="text" name="textfield2" id="textfield2"></td>
</tr>
<tr>
<td colspan="3"><input type="submit" name="submit2" id="submit2" value="Добавить запись">
<input type="submit" name="submit3" id="submit3" value="Показать таблицу">
<input name="submit5" type="submit" id="submit5" value="Отправить"></td>
</tr>
</table></form></div>
Сурс из браузер:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Кулинарная книга</title>
<script type="text/javascript" src="jquery.js"></script>
<script>
function category(category) {
if(category!=0)
$("#category_2").load("category_get.php",{category_2:category});
else
$("#category_2").html("");
}
</script>
<style type="text/css">
.tb {
clear: both;
}
.StyleSelectBox {
width:200px;
height:24px;
font:14px Arial, Tahoma, Helvetica, Verdana;
text-align:left;
background:#fff;
line-height:30px;
white-space:nowrap;
border:1;
zoom:1; }
#selectBoxInfo{
clear:left;
padding:10px;
font:16px "Tahoma";
color:red;}
</style>
</head>
<body>
<h1 style="text-align: center">Кулинарная книга </h1>
<div class="tb">
<form>
<table>
<tr>
<th colspan="3" scope="col">Категория</th>
</tr>
<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>
</tr>
<tr>
<td><input name="category_name" type="text" id="category_name"></td>
<td><input name="category_pid" type="text" id="category_pid"></td>
<td><input name="category_level" type="text" id="category_level"></td>
</tr>
<tr>
<td colspan="3"><input type="submit" formaction="category_add.php" value="Добавить запись">
<input name="submit" type="submit" id="submit" formaction="category_show.php" value="Показать таблицу"></td>
</tr>
</table>
</form>
</div>
<div class="tb"><form><table>
<tr>
<th colspan="3" scope="col">Рецепт</th>
</tr>
<tr>
<td width="77" style="text-align: center; font-weight: bold;">Категория</td>
<td width="144" style="text-align: center; font-weight: bold;">Название</td>
<td width="209" style="text-align: center; font-weight: bold;">Описание</td>
</tr>
<tr>
<td>
<select name="category" id="category" class="StyleSelectBox" onchange="javascript:category(this.value);return false;"><br />
<b>Notice</b>: Undefined index: category in <b>X:\xampp\htdocs\cookbook\index.php</b> on line <b>76</b><br />
<option value="0">- Категория -</option><br />
<b>Notice</b>: Undefined index: category in <b>X:\xampp\htdocs\cookbook\index.php</b> on line <b>83</b><br />
<option value="1">Супы</option><br />
<b>Notice</b>: Undefined index: category in <b>X:\xampp\htdocs\cookbook\index.php</b> on line <b>83</b><br />
<option value="2">Салаты</option></select><br/><select name="category_2" id="category_2" class="StyleSelectBox"></select></td>
<td><input type="text" name="textfield" id="textfield"></td>
<td><input type="text" name="textfield2" id="textfield2"></td>
</tr>
<tr>
<td colspan="3"><input type="submit" name="submit2" id="submit2" value="Добавить запись">
<input type="submit" name="submit3" id="submit3" value="Показать таблицу">
<input name="submit5" type="submit" id="submit5" value="Отправить"></td>
</tr>
</table></form></div>
<div class="tb"><form><table border="0">
<tr>
<th colspan="4" scope="col">Метод приготовления</th>
</tr>
<tr>
<td>Инвентарь</td>
<td>Метод</td>
<td>Номер род. кат.</td>
<td>Уровень</td>
</tr>
<tr>
<td><select name='inv_name'><option>Кастрюля</option><option>Сковорода</option><option>Нож</option></select></td>
<td> </td>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
<tr>
<td colspan="4"><input type="submit" name="submit4" id="submit4" value="Добавить запись"></td>
</tr>
</table>
</form></div>
</body>
</html>
Файл category_get.php
<?php
require('connect.php');
$pid=$_REQUEST["category_2"];
if($pid) {
echo '<option value="0">- Выберите -</option>';
$sql1="select * from category where pid={$pid}";
$ds1=mysqli_query($link,$sql1);
if(mysqli_num_rows($ds1))
while($category_2=mysqli_fetch_array($ds1))
echo '<option value="'.$category_2["id_category"].'">'.$category_2["name"].'</option>';
}
?>