dsiv4041 2014-12-03 09:04
浏览 14
已采纳

创建一个筛选器搜索框到复选框列表 - 动态响应列表

I need to do a form with a long list of item with checkbox for user to tick and pick their options. Because the list has hundreds of item, so to make the search job easy, I thought if I could have a search box act like a filter. when the user enters something, it will filter the list to match the entered text. for example when user enter "A", only items with "A" will be display in the list. the user will repeat searching for item and tick the checkbox on item they wanted. and then when the searchbox is empty, the full list should be displayed. in the end, the user click submit, all the checked item should be post to the next page. (I hope my explanation is clear enough to understand.) Was thinking js "onchange" function might solve the problem but with my limited knowledge on js, I have no idea how to.

For example my code:

<form name="submit" action="envelope.php" method="POST">
                <table width="100%" cellspacing="0" cellpadding="3">
                    <tr>
                        <td></td>
                        <td colspan="2"></td>
                        <td><input type="text" name="search" onchange="filter()"/></td>
                    </tr>
                    <?php
                    $i=0;
                    $str = "SELECT * FROM item ";
                    $query = mysql_query($str) or die(mysql_error());
                    while($row = mysql_fetch_array($query))
                    { 
                        $i++; ?>
                        <tr>
                            <td style="border-bottom: 1px #cccccc solid" width="10">&nbsp;&nbsp;<?php echo $i ?>.</td>
                            <td style="border-bottom: 1px #cccccc solid"><input type="checkbox" name="itm[]" value="<?php echo $row['ID'] ?>"/></td>
                            <td style="border-bottom: 1px #cccccc solid"><?php echo $row['ID'] ?></td>
                            <td style="border-bottom: 1px #cccccc solid"><?php echo $row['name'] ?></td>
                        </tr>
                        <?php
                    } ?>
                </table>
            </div>
            <br/>
            <input type="submit" name="submit" value="submit"/>
        </form>

the input text field would be the search filter. Appreciate if someone could advise. Thank you in advance!

  • 写回答

2条回答 默认 最新

  • dongyi7041 2014-12-03 09:11
    关注

    use datatable.it provide textbox to filter data from table it apply to all column visit below link datatables

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口