dsiv4041 2014-12-03 01: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 01:11
    关注

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

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部