好的,我有这个表单,我想在操作中的值和目录中提交一个页面,这样当选择该选项时,它会打开目录中的页面。
<form method="post" action="pages/">
<ul class="pageitem">
<li class="textbox"><span class="header">Select a specific year</span>
</li>
<li class="select"><select name="pages/">
<option value="1"></option>
<option value="2007.php">2007</option>
<option value="2008.php">2008</option>
<option value="2009.php">2009</option>
<option value="2010.php">2010</option>
<option value="2011.php">2011</option>
<option value="2012.php">2012</option>
</select><span class="arrow"></span>
</li>
<li class="button">
<input name="Submit input" type="submit" value="Submit input" />
</li>
</ul>
</form>
答案 0 :(得分:0)
使用jQuery:
$('select').change(function () {
$(this).closest('form').attr('action', 'pages/' + $('option:selected', this).val());
});
使用PHP(简短版本 - 请注意,您应该删除name =“pages /”上的尾部斜杠)
header('Location: /pages/' + $_POST['pages']);
答案 1 :(得分:0)
<?php
$valid_pages = array("2007","2008","2009","2010","2011","2012");
if(isset($_POST['pages']) && in_array($_POST['pages'], $valid_pages))
{
header("Location: /pages/" . $_POST['pages'] . '.php', true, 303);
exit;
}
?>
和
<form method="post" action="pages">
<ul class="pageitem">
<li class="textbox"><span class="header">Select a specific year</span>
</li>
<li class="select"><select name="pages">
<option value="1"></option>
<option>2007</option>
<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
</select><span class="arrow"></span>
</li>
<li class="button">
<input name="Submit input" type="submit" value="Submit input" />
</li>
</ul>
</form>
答案 2 :(得分:0)
GOT IT!而且我不需要提交按钮。我有一个朋友帮帮我。这是表格:
<script type="text/javascript" src="pages/select.js"></script>
<form method="post" action="pages">
<ul class="pageitem">
<li class="textbox"><span class="header">Select a specific year</span>
</li>
<li class="select">
<select id="select1" onchange="goToPage('select1')">
<option selected="selected"></option>
<option value="pages/2007.php">2007</option>
<option value="pages/2008.php">2008</option>
<option value="pages/2009.php">2009</option>
<option value="pages/2010.php">2010</option>
<option value="pages/2011.php">2011</option>
<option value="pages/2012.php">2012</option>
</select>
<span class="arrow"></span>
</li>
</ul>
</form>
这是select.js:
function goToPage( id ) {
var node = document.getElementById( id );
if( node &&
node.tagName == "SELECT" ) {
window.location.href = node.options[node.selectedIndex].value;
}
}