[英]Auto-submit form with PHP action via JavaScript
如果这个问题很天真,请原谅我。 我是JavaScript的新手,并且正在使用某种形式来显示数据来克服一些挫折。
通过脚本底部JavaScript代码中的$_GET['icao']
,将icao
代码传递到#depicao
<select>
菜单。 在页面加载时, <select>
菜单将填充$_GET['icao']
值。
its populated value. 在后#depicao
<select>
填充菜单,我想的形式其填充值自动提交本身。 我的思路是,如果我包括
document.getElementById("form").submit();
in the script, I can get the script to submit itself it loads with the $_GET['icao']
value. 作为脚本的 ,我可以让脚本加载$_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>
表单自动提交混淆?:
填充#depicao菜单后,我希望表单自动以其填充的值提交自己 。
我对您的理解是,您希望在填充选择菜单时自动提交表单? 我认为您的意思是当用户选择一个选项时,它应该自动提交。 如果这是您的意思。 请在<select>
标记上添加onchange="//submitfunction()"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.