• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Checkboxes and CF

Participant ,
Jul 14, 2009 Jul 14, 2009

Copy link to clipboard

Copied

Hi all, I have  populated checkboxes as follow in a form:

< input type='checkbox' name='Admin_1' value=''>

< input type='checkbox' name='Admin_2' value=''>

< input type='checkbox' name='Admin_3' value=''>....

< input type='checkbox' name='View_1' value=''>

< input type='checkbox' name='View_2' value=''>

< input type='checkbox' name='View_3' value=''>....

...I need to know how to write a cfscript/javascript to check if checkboxes are checked...Then I need to get the first part of  "_"....then update my db tb field

with that new value.

First part of the "_" is a unique key in db..

Example: 

if one checks off admin_1 and admin_3, the string value will be 101 and vice versa... Any help appreciated....

TOPICS
Advanced techniques

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 14, 2009 Jul 14, 2009

Copy link to clipboard

Copied

You are really doing things the hard way.  It would be much easier if you gave all the checkboxes in each group the same name and different values.

I don't quite understand how you get 101 from admin_1 and admin_3.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 14, 2009 Jul 14, 2009

Copy link to clipboard

Copied

Assume each set has same name, then how would you do that?....

and example: 101 means first checkbox and third box are checked not the 2nd...1 means if it is check 0 not check....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2009 Jul 15, 2009

Copy link to clipboard

Copied

Emmim,

Dan was correct in saying that you are doing it the hard way.  Checkboxes mean that there is a natural grouping.  If you want bit values represented whether 1 or 0, I would suggest putting this together on the ColdFusion side.  I would do this by looping through the code like this on the front end:

<cfloop query="recordset">

     <input type='checkbox' name='Admin' value=''#recordset.field#">

</cfloop>

This would create:

     <input type='checkbox' name='Admin' value="1">

     <input type='checkbox' name='Admin' value="2">

     <input type='checkbox' name='Admin' value="3">

     <input type='checkbox' name='Admin' value="4">

on the action page do the following:

<cfset Variables.myNewList = "_">

<cfif isDefined("form.Admin")>

<cfloop query="recordset">

     <cfif Listfind(form.admin,recordset.fieldname)>

           <cfset Variables.myNewList = Variables.myNewList & "1">

     <cfelse>

          <cfset Variables.myNewList = Variables.myNewList & "0">

     </cfif>

</cfloop>

<cfelse>

     <cfset Variables.myNewList = RepeatString(0,recordset.recordCount)>

</cfif>

I prepend the list with an "_" so that it will not convert the string to a number and thus remove any leading 0's.

This will achieve what you are looking for.  However unless there is a VERY specific need to have the characters put in a certain position, I would strongly advise a modified approach.

Sincerely,

Braden

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 15, 2009 Jul 15, 2009

Copy link to clipboard

Copied

How would I know?

Lets say, admin checkbox 1 and 3 are checked...for checked boxes the value will be 1 and not checked 0... Then I need to populate the values of each set as lets say str= 101 then I will update the db field with this new value...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2009 Jul 15, 2009

Copy link to clipboard

Copied

LATEST

Copy and paste the code that I sent you into your pages.  It will work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation