ColdFusion 表单中的复选框 [英] Checkbox in a ColdFusion form

查看:25
本文介绍了ColdFusion 表单中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下.我需要在页面加载时默认选中两个复选框.这将显示查询的结果.现在,当取消选中其中一个复选框时,需要提交表单并显示不同的查询结果.即使我取消选中复选框,也始终选中复选框.有人可以在这里指导我吗?

My code is below. I need to have both of the checkboxes checked by default when the page loads. This displays a result of the query. Now when one of the checkboxes is unchecked the form needs to be submitted and different query results need to be displayed. The checkboxes are always being checked even when I uncheck one. Can someone please guide me here?

<form action="abc.cfm?show=yes" method="post" name="myform">
    <table align="center">
    <tr>
        <td>
            <input type="checkbox" checked="checked" name="chkbox" id="chkbox1"> <strong> Agreement Only</strong> 
            &nbsp;&nbsp;<input type="hidden" name="chk" id="chk1">
            <input type="checkbox" checked="checked" name="chkbox" id="chkbox2"> <strong>Active Employees</strong> 
            &nbsp;&nbsp;<input type="hidden" name="chk" id="chk2">
        </td>
        <td>
            <input type="Submit" name="submitnow" value="View now">
        </td>
    </table>
</form>

<cfif isdefined("form.chk1")>
    query 1
<cfelseif isdefined("form.chk2")>
    query 2
</cfif>

推荐答案

你已经将复选框命名为相同的东西并且总是检查它们,那为什么不检查它们呢?

you've named the checkboxes the same thing and are always checking them, so why would they not be checked?

您需要对它们进行唯一命名,并在提交页面后检查该键是否存在于表单中.或者在表单未提交时显示为选中状态

You need to name them uniquely and check if the key exists in the form once the page has been submitted. Or display the box as checked when the form has not been submitted

表单尚未提交 - NOT structKeyExists(form,'fieldnames')

表单已提交并选择了chkbox1 - structKeyExists(form,'chkbox1')

The form has been submitted and chkbox1 was selected - structKeyExists(form,'chkbox1')

 <td>
   <input type="checkbox"<cfif NOT structKeyExists(form,'fieldnames') OR structKeyExists(form,'chkbox1')> checked="checked"</cfif> name="chkbox1" id="chkbox1"> <strong> Agreement                        Only</strong> 
    &nbsp;&nbsp;<input type="hidden" name="chk" id="chk1">
     <input type="checkbox"<cfif NOT structKeyExists(form,'fieldnames') OR structKeyExists(form,'chkbox2')> checked="checked"</cfif> name="chkbox2" id="chkbox2"> <strong>Active                  Employees</strong> 
   &nbsp;&nbsp;<input type="hidden" name="chk" id="chk2">
  </td>

这篇关于ColdFusion 表单中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆