首页 > 解决方案 > 在 Freemarker 模板语言中单击(选中)复选框时从表中发送两个值

问题描述

        <#if userDatas?? >
            <form action="remove-list" method="POST" autocomplete="on" class="form-horizontal" role="form" id="form1">
                <table class="table table-bordered table-striped">
                <thead>
                <tr>
                    <th class="minwidth">select All <input type="checkbox" onchange="checkAll(this)"> </th>
                    <th>roll no</th>
                    <th>name</th>
                    <th>Created date</th>
                    <th>modified date</th>
                </tr>
                </thead>
                <tbody>
                    <#list userDatas as userData>
                    <tr>
                        <td class="centered-simple"><input type="checkbox" name="entries" value="${userData.roll}" id="${userData.roll}" ></td>
                        <td>${(userData.roll)!notset}</td>
                        <td>${(userData.name)!notset}</td>
                        <td>${(userData.whenCreated?datetime)!notset}</td>
                        <td><code>${(userData.whenModified?datetime)!notset}</code></td>
                    </tr>
                    </#list>
                </tbody>
                </table>
                <div class="btn-group btn-group-tss">
                    <button type="submit" class="btn btn-primary">
                        <span class="glyphicon glyphicon-search"></span> Delete selected 
                    </button>
                </div>
            </form>
        </#if>

在上面的代码片段中,我有一个表,标题为全选、角色、名称、创建日期和修改日期。

当我单击Delete selected按钮时,显然userdata.roll值将被发送。

在这里,我想在单击复选框时同时发送userdata.rolluserdata.name 。

我尝试过,但未能成功。

请帮助我在选中复选框时如何发送这两个值。

PS:我正在使用 FTL 进行编码。

标签: htmlcheckboxhtml-tablefreemarker

解决方案


这不仅仅是一个表格,它是一个表单,“删除选定”按钮是一个提交按钮。提交表单后,所有输入都会发送(在您的案例中发布)。

您可以在表单的任何位置添加隐藏字段

<input type="hidden" name="someParamNameHere" value="${userData.name}" />

如果您只想在单击复选框时发送此值,您可以添加一些基本的 javascript。但我建议你把逻辑放在服务器端。


推荐阅读