I’m doing a bit of CF development, and I was stuck on a problem I had. Instead of banging my head on the keyboard I figured I would ask someone with a bit more experience.
So here’s what I’m dealing with:
<form name="inv" action="action.cfm" method="post" >
<cfoutput query="getQuery">
<input type="checkbox" name="ischecked" value="1" unchecked />
<input type="Hidden" name="DeviceID" value="#DeviceID#">
</td>
<td><font size="3"><b>Device ID:</b></font>#DeviceID#</td>
<td><font size="3"><b>User</b></font>#User#</td>
<td><font size="3"><b>Tag:</b></font>#Tag#</td>
</table>
</cfoutput>
<table>
<tr><td> Action: </td>
<td>
<select name="choose_action">
<option value="1"> Action 1 </option>
<option value="2"> Action 2 </option>
<option value="3"> Action 3 </option>
</select>
<INPUT type="reset" name="reset" action="reset">
<INPUT type="submit" name="submit" action="submit">
</td>
</tr>
So basically I have this form where it outputs all the information from my query (which is working fine) and loops through and displays it. I want the user to be able to look at this information, click a checkbox of the specific device, and perform an action based on the menu at the bottom, which will then go to the action page and use the information passed in to perform queries based on cfif loops.
The problem I’m having is that I can’t figure out how to pass in the information I want that the user specifically checked, because it’s a loop. When I submit the hidden field containing the Device ID, I end up submitting every Device ID that has the checkbox (which is every one). Same goes for the checkbox values. It just dumps all the query data into the action page for each device in the query instead of just the one Device ID I wanted that was checked in the first place.
I was thinking some backend JS, but I wasn’t entirely sure about how I would go about doing that.
I was hoping I could validate it and say, before submission: “well if this is checked, then only submit this specific Device ID”
Thanks for your time and feedback! Let me know if I need to clarify anything.
Here’s 2 answers (and I’ve seen both).
First – try making the device ID part of the “name” of your checkbox.
Then you would loop through form like so:
The second approach would be to store the device ID In the “ischecked” form field like so:
The values come through as a list containing anything checked… so if your user checks 1, 5, and 7 the variagble #form.isChecked# will be a list that looks like 1,5,7. Using listfind or cfloop or whatever to do something with it. Just remember you’ll have to use check to make sure taht form.isChecked exists because if nothing is checked it will not exist (for most browsers).