我确实遇到一个页面上有两个下拉框的问题。因为我必须在没有提交的情况下工作我在“”中使用“onblur = document.getElementById.submit”。这工作正常,但只适用于一个下拉框。对于两个表单使用相同(相等)的代码将导致在选择form2和visa verse中的项目时销毁form1的条目。 形式-1:
<form id="formunit" name="formunit" method="post" action="" >
<select name="cbo_unit" required="required" form="formunit" style="width:100pt" onblur="document.getElementById('formunit').submit();">
<option value="0">--select--</option>
<?php
if ($_POST["cbo_unit"] == "MH") {
echo "<option value=\"MH\" selected=\"selected\">Motorhome</option>";
} else {
echo "<option value=\"MH\">Motorhome</option>";
}
if ($_POST["cbo_unit"] == "RT") {
echo "<option value=\"RT\" selected=\"selected\">Racetruck</option>";
} else {
echo "<option value=\"RT\">Racetruck</option>";
}
?>
</select>
<?php
if(isset($_POST['cbo_unit']) && $_POST['cbo_unit'] > '') {
$unit = $_POST['cbo_unit'];
}
?>
</form>
表2:
<?php
fc_opendb("1","something",$connect);
$dbtable = "course";
$result = mysqli_query($GLOBALS["connect"],"SELECT * FROM " . $dbtable . " WHERE blocked = 'no' ORDER BY matchcode ASC");
?>
<form id="formcourse" name="formcourse" method="post" action="" >
<select name="cbo_course" required="required" form="formcourse" style="width:130pt" onblur="document.getElementById('formcourse').submit();">
<option value="0">--select--</option>
<?php
while ($row = mysqli_fetch_assoc($result)) {
if ($row['matchcode'] == $_POST['cbo_course']) {
$selected = "selected";
} else {
$selected = "";
}
echo '<option value="' . $row['matchcode'] . '"' . $selected . '>' . utf8_encode($row['name']) . ' - ' . utf8_encode($row['place']) . '</option>'."\n";
}
?>
</select>
<?php
if(isset($_POST['cbo_course']) && $_POST['cbo_course'] > '') {
$course = $_POST['cbo_course'];
}
mysqli_close($GLOBALS["connect"]);
?>
</form>