When you initially create the checkbox, it's unchecked; so it'll always be
<input type="checkbox" value="0"...>
But setting the value like that really does nothing for you, because CF only
sees checkboxes when they are checked. So check for
isDefined("form.myCheckboxName") to decide what goes in the database.
Also, not sure all the DOM stuff is necessary... assuming you have some sort of
a list of checkboxes (say, from a db query), here's how I've done it for years:
form:
<cfoutput query="myQuery">
<input type="hidden" name="idList" value="#id#"><!--- multiple form fields
with same name will return as comma-delimited list --->
<input type="checkbox" name="myCheckbox_#id#" value="0"><!--- in most
situations, values doesn't matter, as we only care if it exists or not (only
exists if checked --->
</cfoutput>
processing page;
<cfloop list="#form.idList#" index="iId">
<cfif isDefined('#form.myCheckbox_#iId#')>
<!--- it's checked.. do something --->
<cfelse>
<!--- not checked.. do something else --->
</cfif>
</cfloop>
You can use structKeyExists instead of isDefined if you'd like.
Also, if you're running 9, use ternary operator if you're just interested in
0/1:
'#(isDefined('#form.myCheckbox_#iId#'))?1:0#'
and you can avoid a bunch of redundant code in if-else block
Billy Cravens
> Hi All,
>
> i am trying to insert checkbox value into a database but it seems
> giving me only one state "0" when trying to capture the value in CF.
>
> Here is my CF code where i am trying to capture the check box value
> :
>
> <cfloop from=1 to=#ii# index="i">
> <cfoutput>
> #FORM["Status#i#11"]#
> </cfoutput>
>
> </cfloop>
>
>
> Here is my JavaScript code :
>
>
> Status = document.createElement( 'INPUT' );
> Status.id = 'id' + elementid + (ColumnElement+10);
> Status.type='CheckBox';
> Status.setAttribute('name','Status'+ elementid + (ColumnElement+10));
> if ( Status.checked == false)
> {
> Status.value='0';
> }
> else
> {
> Status.value='1';
> }
>
>
>
> Not sure what i missed ..
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive:
http://www.houseoffusion.com/groups/cf-newbie/message.cfm/messageid:5490
Subscription: http://www.houseoffusion.com/groups/cf-newbie/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-newbie/unsubscribe.cfm