?
Solved

How to organize a large number of checkboxes into columns (using Twitter Bootstrap V3)

Posted on 2015-02-02
5
Medium Priority
?
1,080 Views
Last Modified: 2016-02-25
I have a large number of checkboxes ...

 				<div class="control-group">
					<label for="location" class="control-label">Location: </label>
					<div class="controls">
						<div class="input-append">
							<?php
							
							$tagsdb = explode(',',$_REQUEST['locations']);
							
							foreach ($GLOBALS['all_towns'] AS $tag) {
								$tagid = str_replace(' ', '_', $tag);
								if(in_array($tag, $tagsdb)) $checked = ' CHECKED'; else unset($checked);
								echo "<label class='inline' style='padding-right:8px;'><input type='checkbox' id='location__{$tagid}' name='location[]' value='$tag'{$checked}> $tag</label>";
							}
							?>
						</div>
					</div>
				</div>

Open in new window


What's the best way to automatically organize them into columns...
0
Comment
Question by:Mark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
Rob earned 2000 total points
ID: 40585091
Add the "row" class to your outer <div>.

Add  the relevant column sizing  to each <label> element e.g.

http://jsbin.com/bicogu/1/edit?html,js,output

<div class="input-append row">
      <label class='inline' style='padding-right:8px;'><input type='checkbox' id='location__{$tagid}' name='location[]' value='$tag'>$tag</label>
...
</div>

Open in new window


I've added the class via script but you could easily do this as you're outputting the php

$(function() {
  // for testing, change to col-xs-[num] to see other configurations
  $('.inline').addClass('col-xs-4');
});

Open in new window


in php:
foreach ($GLOBALS['all_towns'] AS $tag) {
	$tagid = str_replace(' ', '_', $tag);
	if(in_array($tag, $tagsdb)) $checked = ' CHECKED'; else unset($checked);
	echo "<label class='inline col-xs-4' style='padding-right:8px;'><input type='checkbox' id='location__{$tagid}' name='location[]' value='$tag'{$checked}> $tag</label>";
}

Open in new window

0
 

Author Comment

by:Mark
ID: 40585334
I will try this in the morning, thanks!
0
 

Author Closing Comment

by:Mark
ID: 40586641
WOW, works perfect, thanks a million
0
 

Author Comment

by:Mark
ID: 40586654
Anyway to make it collapse into one row or two depending on the size of the screen? (on my phone it just bunches together into 3 columns and also some of the checkboxes break off from the labels line:

Example:

[]
My checkbox label
0
 
LVL 43

Expert Comment

by:Rob
ID: 40587321
Sure, just change the class to col-sm instead of xs
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question