我有2个文件: add.php (用于将配方添加到数据库中的表单,以及 numbers.php (用于显示成分选项的列表)。< / p>
两个脚本/页面都是单独工作的...但是当我包含('numbers.php')时,onchange代码不起作用。
//numbers.php
<form name="numbers" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="select" onchange="javascript: document.numbers.submit();">
<option value=0>-</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
</select>
</form>
<?php
$num_ingredients = $_REQUEST["select"];
$count = 0;
while ($count < $num_ingredients) {
$count++;
include ('../ingredients/list.php');
echo '<br />';
}
?>
//add.php
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
Recipe Title:
<input type="text" name="recipe_name" maxlength="30" value="<?php echo $recipe_name; ?>" /><br />
Ingredients:
<?php include ('numbers.php'); ?><br />
<input type="submit" value="Add Recipe" />
<input type="button" onclick="history.go(0)" value="Clear" /><br />
</form>
任何帮助都非常感谢,一如既往:)
-------编辑-------------------------------------- < / p>
以下是add.php请求的页面源
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta http-equiv="Content Type" content="text/html; charset=UTF-8" />
<title>POWERCHEF</title>
<meta name="robots" content="noindex, nofollow">
<meta name="distribution" content="iu">
<meta name="format-detection" content="telephone=yes">
<meta name="copyright" content="Copyright 2012">
</head>
<body>
<!-- ON WITH THE SHOW --><h3>ADD RECIPE</h3><html>
<form enctype="multipart/form-data" action="/kitchen/recipes/add.php" method="POST">
Recipe Title:
<input type="text" name="recipe_name" maxlength="30"
value="" /><br />
Subtitle:
<input type="text" name="recipe_subtitle" maxlength="50"
value="" /><br />
Category:
<input type="text" name="recipe_category" maxlength="50"
value="" /><br />
Subcategory:
<input type="text" name="recipe_subcategory" maxlength="50"
value="" /><br />
<br />
Photo:<br />
<input type="hidden" name="MAX_FILE_SIZE" value="200000" />
<input type="file" name="recipe_photo" value="" /><br />
<br />
Ingredients:<br />
<form name="numbers" method="post"
action="/kitchen/recipes/add.php">
<select name="select" onchange="javascript: document.numbers.submit();">
<option value=0>-</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=10>10</option>
<option value=11>11</option>
<option value=12>12</option>
<option value=13>13</option>
<option value=14>14</option>
<option value=15>15</option>
<option value=16>16</option>
<option value=17>17</option>
<option value=18>18</option>
<option value=19>19</option>
<option value=20>20</option>
<option value=21>21</option>
<option value=22>22</option>
<option value=23>23</option>
<option value=24>24</option>
<option value=25>25</option>
<option value=26>26</option>
<option value=27>27</option>
<option value=28>28</option>
<option value=29>29</option>
<option value=30>30</option>
</select>
</form>
<br />
<br />
Prep Instructions:<br />
<textarea name="recipe_prep_instructions" class="" cols="88" rows="15"
value="" /></textarea><br />
<br />
Cooking Instructions:<br />
<textarea name="recipe_prep_instructions" class="" cols="88" rows="15"
value="" /></textarea><br />
<br />
<input type="submit" value="Add Recipe" />
<input type="button" onclick="history.go(0)" value="Clear" /><br />
<br />
</form>
</html>
<footer>
<p>
<small><strong>© 2012 </strong> - All Rights Reserved</small>
</p>
</footer>
<!-- THANKS FOR STOPPING BY! -->
</body>
</html>
答案 0 :(得分:2)
你有一个错字:
<input type="text" name="recipe_name" maxlength="30" value="<?php echo $recipe_name"; ?>" /><br />
应该是:(注意删除php块中的引用)
<input type="text" name="recipe_name" maxlength="30" value="<?php echo $recipe_name; ?>" /><br />
引用可能会弄乱另一个脚本。
编辑: 好吧,这也只是一个复制粘贴错字?
<form name="numbers" method="post action="<?php echo $_SERVER['PHP_SELF']; ?>">
应该是:
<form name="numbers" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
EDIT2:
好吧,问题是表单“数字”在另一个表单中,因此无法使用document.numbers
访问它。要解决此问题,您需要以不同的方式访问它,例如为其提供ID并使用getElementById
。
答案 1 :(得分:0)
add.php上的表单没有名称