如果这个问题很幼稚,请原谅我。我是JavaScript的新手,正在通过一些我用来显示数据的表单来学习一些挫折。
icao
代码通过脚本底部的JavaScript代码中的#depicao
传递到<select>
$_GET['icao']
菜单。在页面加载时,<select>
菜单将填充$_GET['icao']
值。
填充#depicao
<select>
菜单后,我希望表单自动提交 其填充值。我的思路是,如果我包括
document.getElementById("form").submit();
作为脚本中的最后一行,我可以让脚本在之后提交,并加载$_GET['icao']
值。不幸的是,这并没有奏效。
注意:该代码包含多个 <input type="submit" name="submit">
按钮。我相信这是罪魁祸首。
见下面的代码。
<form id="form" action="<?php echo actionurl('/schedules/view');?>" method="post">
<div id="tabcontainer">
<ul>
<li><a href="#depapttab" onclick="formReset()"><span>Via departure airport</span></a></li>
<li><a href="#arrapttab" onclick="formReset()"><span>Via arrival airport</span></a></li>
</ul>
<div id="depapttab">
<select id="depicao" name="depicao">
<option value="">Select All</option>
<?php
$exclude = array(13, 18, 19, 22); // Airport IDs found in phpVMS_airports not to be included in the dropdown menu
if(!$depairports) $depairports = array();
foreach($depairports as $airport) {
if(!in_array($airport->id, $exclude)) { // Exclude values in the above array from the dropdown menu
echo '<option value="'.$airport->icao.'">'.$airport->icao.' - '.$airport->name.'</option>';
}
}
?>
</select>
<input type="submit" name="submit" value="Find Flights" />
</div>
<div id="arrapttab">
<select id="arricao" name="arricao">
<option value="">Select All</option>
<?php
$exclude = array(13, 18, 19, 22); // Airport IDs found in phpVMS_airports not to be included in the dropdown menu
if(!$depairports) $depairports = array();
foreach($depairports as $airport) {
if(!in_array($airport->id, $exclude)) { // Exclude values in the above array from the dropdown menu
echo '<option value="'.$airport->icao.'">'.$airport->icao.' - '.$airport->name.'</option>';
}
}
?>
</select>
<input type="submit" name="submit" value="Find Flights" />
</div>
</div>
<input type="hidden" name="action" value="findflight" />
</form>
<script type="text/javascript">
function formReset() {
document.getElementById("form").reset();
}
function setSelectedIndex(s, valsearch) {
// Loop through all the items in drop down list
for (i = 0; i< s.options.length; i++) {
if (s.options[i].value == valsearch) {
// Item is found. Set its property and exit
s.options[i].selected = true;
break;
}
}
return;
}
setSelectedIndex(document.getElementById("depicao"),"<?php if(isset($_GET['icao'])) { echo $_GET['icao']; } else { echo 'Select All'; } ?>");
document.getElementById("form").submit();
</script>
答案 0 :(得分:0)
表单自动提交混淆?:
填充#depicao菜单后,我希望表单自动提交及其填充值。
我如何理解您是否希望在填充选择菜单时自动提交表单?我认为你的意思是当用户选择一个选择时,它应该自动提交。如果这是你的意思。请在onchange="//submitfunction()"
代码
<select>