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
The form has not been submitted - NOT structKeyExists(form,'fieldnames')
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>