0

Okay, I have this form and I want to submit a page in the value and a directory in the action so when the option is selected it opens the page thats in the directory.

<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>
4

3 回答 3

0

知道了!而且我不需要提交按钮。我有一个朋友帮助我。这是表格:

<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;

   }


}
于 2012-12-05T23:50:30.277 回答
0

使用 jQuery:

$('select').change(function () {
    $(this).closest('form').attr('action', 'pages/' + $('option:selected', this).val());
});

使用 PHP(短版 - 注意你应该删除 name="pages/" 上的斜杠)

header('Location: /pages/' + $_POST['pages']);
于 2012-12-05T22:09:28.573 回答
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>
于 2012-12-05T22:14:36.210 回答