Checkbox in a ColdFusion form(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>
<input type="hidden" name="chk" id="chk1">
<input type="checkbox" checked="checked" name="chkbox" id="chkbox2"> <strong>Active Employees</strong>
<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>
<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>
<input type="hidden" name="chk" id="chk2">
</td>
这篇关于ColdFusion 表单中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ColdFusion 表单中的复选框
基础教程推荐
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01