2017-03-02 62 views
-3

我有上面的表格,上面有一个选择器(带有2个选项,oldeste和newest“。当我选择”最老的“时,它将最老的元素放在上面,当我选择最新它把上面的最新alements 在HTML我的表ID是“MYTABLE”我有一个名为日期字段,这是我的代码如何在选择器中选择一个选项并更新我的表格

<form action="" method="post"> 
       <center> <b>Filter: <b><select name="select1"> 
        <option value="value1">by Oldest</option> 
        <option value="value5">by Newest</option> 
       </select></center> 
       <br> 
       <center> <input type="submit" name="submit" value="Filter"/> </center> 
       <br> 
       </form> 
       <?php 
       if(isset($_POST['select1'])){ 
       $select1 = $_POST['select1']; 
       switch ($select1) { 
        case 'value1':?> 

    //something 

        <?php break; ?> 
        <?php case 'value2': ?> 

    //something 
        <?php break; ?> 

        <?default: 

        break; 
       } 
       } 
       ?> 

回答

0

第一组ID选择:。 <select name="select1" id="selectlist">

尝试类似的方式获得价值:

var selectBox = document.getElementById("selectlist"); var selectedValue = selectBox.options[selectBox.selectedIndex].value;

现在你知道你在selectedValue中选择了什么。

然后,你必须设置的onchange parametr:

onchange="function()"

并让功能在JavaScript编辑。

相关问题