doulan3436 2015-08-28 06:46
浏览 39
已采纳

POST到PHP弹出窗口的可点击HTML表格行

I have an HTML table that has rows generated with PHP and populated with MySQL data. I want the rows to be clickable, where onclick they open a new window with the MySQL data for that row.

What method can I use to POST a value on click and open the PHP page in a new window without disturbing the parent page? My rows are generated similar to this:

while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    echo "
        <tr onclick=\"openDetails(" . $row['id'] . ")\"> //openDetails() does nothing for now…
        <td>" . $row['id'] . "</td>
        <td>" . $row['ser'] . "</td>
        <td>" . $row['part'] . "</td>
        <td>" . $row['model'] . "</td>
        <td>" . $row['make'] . "</td>
        <td>" . $row['description'] . "</td>
        <td>" . $row['price'] . "</td>
    </tr>";

openDetails(); does nothing but I thought JS (I'm open to JQuery solutions) was the key. The overall idea is that someone clicks the row and they get assets_details.php (Which will query for WHERE id=$_POST['id'] and populate a form) in a new window where they can edit and submit the information. If POST isn't possible a $_SESSION variable would do, I just don't know how to set either "onclick".

  • 写回答

3条回答 默认 最新

  • douji5397 2015-08-28 08:20
    关注

    Thanks @RamRaider for the suggestions but I know nothing of ajax and I'm afraid to use code that I don't fully understand.

    I came up with this solution though. I wrapped the table in a form and created a hidden input that is set and submitted onclick for the row.

    <form target='_blank' name='getID' method='POST' action='asset_details.php'>
    <input type='hidden' name='id' id='id'>
    <table>
    while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
        echo "
            <tr onclick=\"selectID('" . $row['id'] . "')\">
                <td>" . $row['id'] . "</td>
                <td>" . $row['ser'] . "</td>
                <td>" . $row['part'] . "</td>
                <td>" . $row['model'] . "</td>
                <td>" . $row['make'] . "</td>
                <td>" . $row['description'] . "</td>
                <td>" . $row['price'] . "</td>
            </tr>
    </table>
    </form>";
    

    The JS:

    function selectID(id) {
        document.getID.id.value = $(this).closest('tr').attr('id');
        document.getElementsByName('getID')[0].submit();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

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

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

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

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

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

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

客服 返回
顶部