在PHP中提交onChange
我应该如何在“select”元素上正确刷新PHP页面 在我的作业中,我有两个组合框1)车辆类型和2)特定于该类型的颜色 每次选择一种类型时,我都需要重新设置链接颜色 似乎在PHP中提交onChange,php,Php,我应该如何在“select”元素上正确刷新PHP页面 在我的作业中,我有两个组合框1)车辆类型和2)特定于该类型的颜色 每次选择一种类型时,我都需要重新设置链接颜色 似乎onchange=“this.form.submit()”不起作用 这是我的代码: <?php include_once ("config.php"); $link = mysql_connect($host,$user,$pass) or die("Could not connect : " . mysql_error
onchange=“this.form.submit()”
不起作用
这是我的代码:
<?php
include_once ("config.php");
$link = mysql_connect($host,$user,$pass) or die("Could not connect : " . mysql_error());
mysql_select_db($db_name) or die("Could not select database");
?>
<html>
<head>
</head>
<body>
<?php
$menu_type=$_POST['menu_type'];
echo 'menu_type='.$menu_type.'<br/>';
echo 'empty='.(bool)empty($menu_type).'<br/>';
echo '-1='.(bool)($menu_type==-1);
?>
<table>
<form name="myform" action="ajoute.php" method="POST" >
<tr>
<td>Matricule</td>
<td><input type="text" value="" style="width:150px;" name="Matricule"></td>
</tr>
<tr>
<td>Vehicule</td>
<td>Couleur</td>
</tr>
<tr>
<td><select name="menu_type" style="width:150px;" onchange="this.form.submit()">
<option value="-1">Select voiture type</option>
<?php
$resType = mysql_query("SELECT * FROM type_vehicule") or die(mysql_error());
for ($i=0; $i<mysql_num_rows($resType); $i++)
{
$row=mysql_fetch_array($resType);
echo "<option value = ".$row['ID'].">".$row['nom']."</option>";
}?>
</select>
</td>
<td>
<?php
echo "empty = ".(bool)empty($menu_type)."; $menu_type = ".$menu_type;
?>
<select name="menu_couleur" size="1" style="width:150px;">
<?php
if (empty($menu_type) || $menu_type == -1)
{
echo "<option value='-1'>Select voiture type</option>";
}
else
{
$type=(int)$menu_type;
$result=mysql_query("SELECT c.Id, c.Couleur FROM couleur c inner join
type_couleur tc on c.id=tc.Couleur_ID where tc.type_id=".$type);
while ($row = mysql_fetch_array($result)) {
echo "<option value=".$row['ID'].">".$row['couleur']."</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td align="right" colspan=2><input type="submit" name="submit" value="Valide"></td>
</tr>
</form>
</table>
<?php
mysql_free_result($resType);
mysql_close($link);
?>
</body>
</html>
矩阵
车辆
库勒
选择voiture类型
问题是因为您将提交按钮命名为submit(即name=“submit”)。因此,当您执行this.form.submit()时,它试图对html元素执行一个函数
在chrome javascrip控制台中,我得到一个错误:
document.formname.submit不是未捕获类型的函数错误:对象#HTMLForm元素的属性“submit”不是函数
做了谷歌搜索,找到了这个解释一切的页面:
因此,要解决问题,只需删除submit按钮中的name=“submit”或将其命名为其他名称,如name=“submitButton”。首先,您将表单写入了表标记中,这是不正确的。 应该是这样的
<form>
<table>
...
</table>
</form>
...
以HTML格式获取输出,并查看控制台中是否存在javascript错误,以便于识别。同时检查提交按钮名称。是否存在javascript错误?(与firebug一起检查)onchange看起来是正确的,并且在这里工作,否则请尝试getElementById('formidtarget')。submit();在添加了id之后,我还注意到,当页面重新加载时,您没有机制重新选择“菜单类型”中的值?我可以在POST中区分单击验证(提交)按钮和更改组合框吗?