Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
ldonner #1
Reading Dynamic Checkbox values
I have a resultset which has a Boolean field that I display in a table, however
I am having a problem trying to update the data for these checkboxes. I have
used a combination for the checkbox name but I am unable to read the values
assigned to the checkboxes due to the inherent nature of FORMS. Does anyone
know of a way to display boolean values using checkboxes and change/update the
data to the database?
Thanks.
ldonner Guest
-
Losing checkbox values when saving PDF
Hi, I have been looking at this problem for 2 days now, changing numerous properties and trying different coding approaches and nothing works. ... -
How to bind checkbox to one of the values of a datagrid
Hello All, I hope someone can enlighten me, all of the examples and posts Ihave read and sifted through doesn't pertain to what i wouldlike to do... -
pass dynamic checkbox values to results page?
ASP VB Access db Help! I'm trying to pass the results of dynamic checkboxes to a results pages. What's the easiest way to get this accomplished?... -
[PHP] retrieving form checkbox values
This is not necessary, you can do foreach($_POST as $file) { // ... } George Pitcher wrote: -
retrieving form checkbox values
I have a form which I want to post multiple values from one function to another using checkboxes. Having one value is simple- the form submits the... -
-
mattw #3
Re: Reading Dynamic Checkbox values
For display:
<input type="checkbox" name="myCheckbox" <cfif myQuery.myCheckbox EQ
1>checked</cfif>>
On action page:
<cfquery....>
Update myTable
SET myCheckbox = #IIf(IsDefined("myCheckbox"),1,0)#
WHERE myID...
</cfquery>
mattw Guest
-
The ScareCrow #4
Re: Reading Dynamic Checkbox values
You need to approch this in 2 ways.
First thing is to call the checkboxes all the same name. Then in the value
attribute of the checkbox insert the id of the record.
Then in the action page
<!--- Process all the checkboxes that are defined (ie checked) --->
Update myTable
Set myBitField = 1
Where id IN (#form.CheckBoxName)#
<!--- Process all the checkboxes that are not defined (ie not checked) --->
Update myTable
Set myBitField = 1
Where id NOT IN (#form.CheckBoxName)#
Ken
The ScareCrow Guest
-
franzo #5
Re: Reading Dynamic Checkbox values
Hi,
Include <cfparam name="mycheckbox" default="0"> in your action page, before
the SQL statement.
If your checkbox is checked it will submit the correct value "1" to your
action page. If it is not checked then no value is submited and the default
value from the cfparam is used.
Cheers,
Fober
franzo Guest
-
ldonner #6
Re: Reading Dynamic Checkbox values
What I am trying to do is show a meritbadge from a menu list that then shows
all the adult leaders and whether or not they can counsel scouts on that merit
badge. Here is my code so far.
Thanks
<!--- Update all checkboxes that are defined (ie checked) --->
<cfquery name="updateAdultMDYes" datasource="MySrc">
UPDATE Adult2MB
SET Capability="Yes"
WHERE ID IN(#FORM.Status#)
</cfquery>
<!--- Update all checkboxes that are not defined (ie not checked) --->
<cfquery name="updateAdultMBNo" datasource="MySrc">
UPDATE Adult2MB
SET Status="No"
WHERE ID NOT IN(#FORM.Status#)
</cfquery>
</cfif>
<cfquery name="getMeritBadges" datasource="MySrc">
SELECT *
FROM MeritBadges
ORDER BY Name DESC
</cfquery>
<cfquery name="getAdults" datasource="MySrc">
SELECT *
FROM Adults
ORDER BY Name DESC
</cfquery>
<cfquery name="getAdult2MB" datasource="MySrc">
SELECT MB_ID, Adult_ID
FROM Adult2MB
WHERE MB_ID = '#FORM.MB_ID#'
</cfquery>
<html>
<head>
<title>Administration Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="joist.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="titleCap">Administration</div>
<br>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr align="center">
<td class="StoryTitle">Update Counselors to Merit Badges</td>
</tr>
<tr align="center">
<td>
<form method="POST" name="UpdateData">
<table width="90%" border="0" cellpadding="0" cellspacing="0">
<tr class="StoryTitle">
<td width="30%" class="center"><select name="MB_ID"
onChange="this.form.submit();">
<cfoutput query="getMeritBadges">
<option value="#getMeritBadges.ID#" <cfif
(isDefined("FORM.MB_ID") AND FORM.MB_ID EQ
getMeritBadges.ID)>selected</cfif>>#getMeritBadges.Name#</option>
</cfoutput>
</select>
</td>
<td width="30%" class="center">Adult Name</td>
<td width="30%">Yes?</td>
</tr>
<cfoutput query="getAdults">
<tr>
<td> </td>
<td>#getAdults.Name#</td>
<td>
<cfif getAdults.ID EQ EQ getAdult2MB.Adult_ID>
<input name="Status" type="checkbox" value="#getAdults.ID#"
checked>
<cfelse>
<input name="Status" type="checkbox" value="#getAdults.ID#">
</cfif>
</td>
</tr>
</cfoutput>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td> </td>
<td colspan="2">
<input name="UpdateData" type="submit" value="Submit">
<input name="Reset" type="reset" value="Reset">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
ldonner Guest
-
The ScareCrow #7
Re: Reading Dynamic Checkbox values
You don't indicate if your code is working or giving errors and if errors what
are they.
But, it appears that you submit the form back to itself. So you should not be
doing the db updates unless the form has been submitted.
<cfif isdefined("form.UpdateData")>
<!--- Update all checkboxes that are defined (ie checked) --->
<cfquery name="updateAdultMDYes" datasource="MySrc">
UPDATE Adult2MB
SET Capability="Yes"
WHERE ID IN(#FORM.Status#)
</cfquery>
<!--- Update all checkboxes that are not defined (ie not checked) --->
<cfquery name="updateAdultMBNo" datasource="MySrc">
UPDATE Adult2MB
SET Status="No"
WHERE ID NOT IN(#FORM.Status#)
</cfquery>
</cfif>
Also after the 2 update queries you have a closing </cfif> tag, but I can't
see the opening tag to match.
You have the following code
<cfif getAdults.ID EQ EQ getAdult2MB.Adult_ID>
While your looping through the getAdults record set you don't loop through the
getAdult2MB recordset, so it will only ever check the first record. I think
you want to do
<cfoutput query="getAdults">
<tr>
<td> </td>
<td>#getAdults.Name#</td>
<cfloop query="getAdult2MB">
<td>
<input name="Status" type="checkbox" value="#getAdults.ID#" <cfif
getAdults.ID EQ EQ getAdult2MB.Adult_ID>checked</cfif>>
</td>
</cfloop>
</tr>
</cfoutput>
Ken
The ScareCrow Guest
-
blkcop #8
Re: Reading Dynamic Checkbox values
Trying to do something very similar, but ONLY want them to be able to check 1
box on the page, which would then (on submit) send user to another page to
conduct updates of file. All of my checkboxes would have the same name
(ie-MOD_#id#) as they are being dynamically assigned from a query.
blkcop Guest
-
The ScareCrow #9
Re: Reading Dynamic Checkbox values
blkcop,
Is this a plain html/cfm page ?
If so you can do this using javascript.
See code attached, which is untested
Ken
function checkOne(clickedBox, totalBoxes){
for(i=1;i=toalBoxes;i++){
if(document.getElementById("MOD_" + i).checked && i != clickedBox){
// this will uncheck any box that is checked and then check the box
that was clicked
document.getElementById("MOD_" + i).checked = false;
document.getElementById("MOD_" + clickedBox).checked = true;
}
}
}
}
<!--- then with each checkbox you have an onclick event
<input type="checkbox" name="MOD_#currentrow#"
onclick="checkOne('#currentrow#', '#recordcount#');">
The ScareCrow Guest



Reply With Quote

