[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

Outputting Checkboxes In Table Format

With the code below i can output 3 checkboxes to a table row: -

                 A         B         C
                 D         E         F
                 G         H        I

I am looking to change the layout to the following:  -

                A          D         G
                B          E          H
                C          F          I
 
<table cellpadding="0" cellspacing="0" border="0">
   <!--- Output  Sectors --->
   <cfoutput query="Get_Sectors">
      <cfif CurrentRow MOD 3 eq 1><tr align="left"></cfif>
      <td width="2%"><input type="Checkbox" name="sectors" value="#Get_Sectors.sectorid#" <CFIF FORM.sectors contains    
      Get_Sectors.sectorid>CHECKED="yes"</cfif>></td>
      <td class="tdleft" nowrap="yes" width="20%">#Get_Sectors.sector#</td>
      <cfif currentRow MOD 3 eq 0 OR currentRow eq recordcount></tr></cfif>
   </cfoutput>
</table>

Any advice on how to accomplish this would be much appreciated

JT
0
jturkington
Asked:
jturkington
  • 11
  • 8
  • 2
2 Solutions
 
CFDevHeadCommented:
here try this

<table cellpadding="0" cellspacing="0" border="0">
   <!--- Output  Sectors --->
   <tr align="left">
   <cfoutput query="Get_Sectors">
      <cfif CurrentRow MOD 3 eq 1> <td width="2%"><table></cfif>
        <tr>
        <td>
     <input type="Checkbox" name="sectors" value="#Get_Sectors.id#"></td>
      <td class="tdleft" nowrap="yes" width="20%">#Get_Sectors.sector#</td>
        </tr>
      <cfif currentRow MOD 3 eq 0 OR currentRow eq recordcount></table></td></cfif>
   </cfoutput>
   </tr>
</table>
0
 
mrichmonCommented:
Is there a reason to have them in the separate rows?

----------------------------
|      A       |       D       |
----------------------------
|      B       |       E       |
----------------------------
|      C       |       F       |
-----------------------------

Could you do:

----------------------------
|      A       |       D       |
|      B       |       E       |
|      C       |       F       |
-----------------------------

If so then try:

<table cellpadding="0" cellspacing="0" border="0">
   <!--- Output  Sectors --->
   <cfoutput query="Get_Sectors">
      <cfif CurrentRow MOD 3 eq 1><tr align="left"><td width="2%"></cfif>
      <input type="Checkbox" name="sectors" value="#Get_Sectors.sectorid#" <CFIF FORM.sectors contains    
      Get_Sectors.sectorid>CHECKED="yes"</cfif>> #Get_Sectors.sector#<br>
      <cfif currentRow MOD 3 eq 0 OR currentRow eq recordcount></td></tr></cfif>
   </cfoutput>
</table>

0
 
mrichmonCommented:
Whoops - slight modification

<table cellpadding="0" cellspacing="0" border="0">
<tr align="left">
   <!--- Output  Sectors --->
   <cfoutput query="Get_Sectors">
      <cfif CurrentRow MOD 3 eq 1><td width="2%"></cfif>
      <input type="Checkbox" name="sectors" value="#Get_Sectors.sectorid#" <CFIF FORM.sectors contains    
      Get_Sectors.sectorid>CHECKED="yes"</cfif>> #Get_Sectors.sector#<br>
      <cfif currentRow MOD 3 eq 0 OR currentRow eq recordcount></td></cfif>
   </cfoutput>
</tr>
</table>
0
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
jturkingtonAuthor Commented:
Thanks Mrichmon, i only want three checkboxes to appear on each row how do i achieve this with your above solution ?
0
 
CFDevHeadCommented:
did you look at my solution above it does what you want it to do
0
 
jturkingtonAuthor Commented:
Sorry CFDevHead , just tried it there ....

It works , but as with mrichmon solution i only want to have three checkboxes on each row, so for example if i have 30 checkboxes that would mean 3 columns with 10 rows .. right ??

Sorry for this, its more complicated than i thought !!

JT

0
 
CFDevHeadCommented:
here I modified it to do what you would like it to do
<cfset cnt =1>
<table cellpadding="0" cellspacing="0" border="0">
   <!--- Output  Sectors --->
   <tr align="left">
   <cfoutput query="Get_Sectors">
      <cfif CurrentRow MOD 3 eq 1>
                    
            <cfif cnt is 4>
                  </tr><tr>
                  <cfset cnt =1>
            </cfif>
            <cfset cnt =1+cnt>
              <td width="2%"><table>

      </cfif>
        <tr>
        <td>
     <input type="Checkbox" name="sectors" value="#Get_Sectors.id#"></td>
      <td class="tdleft" nowrap="yes" width="20%">#Get_Sectors.cb#</td>
        </tr>
      <cfif currentRow MOD 3 eq 0 OR currentRow eq recordcount></table></td></cfif>
        
   </cfoutput>
   </tr>
</table>

http://think-lab.net/ee.cfm
0
 
jturkingtonAuthor Commented:
Its close..  say there is 10 checkboxes, maybe do some recordcount / 3  = 3.333

so ..

A     E    H  
B     F     I
C    G     J
D

Sorry if i am confusing you here !!

JT
0
 
CFDevHeadCommented:
there you go something like this should work

<cfset cnt =1>

<table cellpadding="0" cellspacing="0" border="0">
   <!--- Output  Sectors --->
   <tr align="left">
   <cfoutput query="Get_Sectors">
      <cfif CurrentRow MOD round(Get_Sectors.recordcount/3) eq 1>
                    
            <cfif cnt is 4>
                  </tr><tr>
                  <cfset cnt =1>
            </cfif>
            <cfset cnt =1+cnt>
              <td width="2%"><table border="0">

      </cfif>
        <tr>
        <td width="2%">
     <input type="Checkbox" name="sectors" value="#Get_Sectors.id#"></td>
      <td class="tdleft" nowrap="yes" width="20%">#Get_Sectors.cb#</td>
        </tr>
      <cfif currentRow MOD round(Get_Sectors.recordcount/3) eq 0 OR currentRow eq recordcount></table></td></cfif>
        
   </cfoutput>
   </tr>
</table>
0
 
jturkingtonAuthor Commented:
Yes it looks like its working !!, but i am getting weird formatting results with only 3 checkboxes !!

Ahh so close !!

JT
0
 
jturkingtonAuthor Commented:
with 3 checkboxes it should have one row with three columns, its putting the first checkbox on a row and the second and third checkbox on the second row ?!?

JT
0
 
CFDevHeadCommented:
<cfset cnt =1>
<cfset tmp=round(Get_Sectors.recordcount/3)>
<cfif tmp le 3>
<cfset tmp=3>
</cfif>
<table cellpadding="0" cellspacing="0" border="0">
   <!--- Output  Sectors --->
   <tr align="left">
   <cfoutput query="Get_Sectors">
      <cfif CurrentRow MOD tmp eq 1>
                    
            <cfif cnt is 4>
                  </tr><tr>
                  <cfset cnt =1>
            </cfif>
            <cfset cnt =1+cnt>
              <td width="2%"><table border="0">

      </cfif>
        <tr>
        <td width="2%" align="right">
     <input type="Checkbox" name="sectors" value="#Get_Sectors.id#"></td>
      <td class="tdleft" nowrap="yes" width="20%">#Get_Sectors.cb#</td>
        </tr>
      <cfif currentRow MOD tmp eq 0 OR currentRow eq recordcount></table></td></cfif>
        
   </cfoutput>
   </tr>
</table>
0
 
jturkingtonAuthor Commented:
Yes!.. No.. Last example i was getting a division by zero error with only one checkbox LOL !!

Okay with three checkboxes its putting them on three separate rows, is it possible to put them all on the one row !?

Im pushing my luck here !

JT
0
 
CFDevHeadCommented:
this will take care of the division by zero
<cfset cnt =1>
<cfset tmp=1>
<cfif Get_Sectors.recordcount gt 0>
      <cfset tmp=round(Get_Sectors.recordcount/3)>
      <cfset tmp=3>
</cfif>
<cfif tmp le 3>
      <cfset tmp=3>
</cfif>
<table cellpadding="0" cellspacing="0" border="0">
   <!--- Output  Sectors --->
   <tr align="left">
   <cfoutput query="Get_Sectors">
      <cfif CurrentRow MOD tmp eq 1>
                    
            <cfif cnt is 4>
                  </tr><tr>
                  <cfset cnt =1>
            </cfif>
            <cfset cnt =1+cnt>
              <td width="2%"><table border="0">

      </cfif>
        <tr>
        <td width="2%" align="right">
     <input type="Checkbox" name="sectors" value="#Get_Sectors.id#"></td>
      <td class="tdleft" nowrap="yes" width="20%">#Get_Sectors.cb#</td>
        </tr>
      <cfif currentRow MOD tmp eq 0 OR currentRow eq recordcount></table></td></cfif>
        
   </cfoutput>
   </tr>
</table>
0
 
jturkingtonAuthor Commented:
I think the code is getting a little confusing here !!

Okay is there a simple way just to assume there will be always three columns and 5 checkboxes to a column !?

so ...

A                            F                       K
B                            G                       L
C                            H                       M
D                            I                        N
E (New Column)      J(New Column)    o
                                                       P
                                                       q
                                                       r etc...

Thanks for your patience CFDevHead its much appreacited :-)
0
 
CFDevHeadCommented:
as for this "Okay with three checkboxes its putting them on three separate rows, is it possible to put them all on the one row !?"
Please post another question
0
 
CFDevHeadCommented:
On this line
 <td width="2%"><table border="0">

change it to

<td width="2%" valign="top"><table border="0">
0
 
CFDevHeadCommented:
I saw that you opened another question are you going to award points for this question?
0
 
CFDevHeadCommented:
are you still working on this
0
 
CFDevHeadCommented:
Are you still working on this
0
 
jturkingtonAuthor Commented:
Yes sorry, CFDevHeasd got side tracked will update the post ASAP !
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 11
  • 8
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now