473,597 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Split long list of list items

Hello All,

I am trying to split a long list of list items ( li ) into 3 groups and
append them to a div on the page. Below is the test page that I have
created. It's fairly simple but I can't seem to get my head wrapped around
it. Anyone here can offer a boost?

http://mysite.verizon.net/microweb2/3collist.html

David J.
Aug 25 '06 #1
7 2449
Or basically, how can you split an array into spearate groups by dividing
the length of the array by 3. If the array has 15 entries, how can I grab 3
chunks of 5 out of the 15 ?

David J.


"David" <ri***@dd.comwr ote in message news:cUtHg.4561 $0J6.3005@trndd c02...
Hello All,

I am trying to split a long list of list items ( li ) into 3 groups and
append them to a div on the page. Below is the test page that I have
created. It's fairly simple but I can't seem to get my head wrapped around
it. Anyone here can offer a boost?

http://mysite.verizon.net/microweb2/3collist.html

David J.

Aug 25 '06 #2
David wrote:
Hello All,

I am trying to split a long list of list items ( li ) into 3 groups and
append them to a div on the page. Below is the test page that I have
created. It's fairly simple but I can't seem to get my head wrapped around
it. Anyone here can offer a boost?

http://mysite.verizon.net/microweb2/3collist.html
In the line:
var container = document.getEle mentByID('write Me');

You have the wrong capitalisation for getElementById( )

I think what you are trying to do is divide the li elements evenly
between 3 ul elements. If so, you need to work out how many to put
into each ul, then do it. Rather than try to munge the script you have,
I'll just post the following script give you some pointers:

function quickTest()
{
var numSections = 3; // Number of sections
var numPerSection; // Number in each section (calculate)
var extras = 0; // Remainder if not equal number
// in all sections

var oUL; // New ul element
var div = document.getEle mentById('pCont ent');
var ul = div.getElements ByTagName('ul')[0];
var lis = ul.getElementsB yTagName('li');
var numPerSection = lis.length/numSections | 0;

if (numPerSection) {
extras = lis.length % numSections;
} else {
numPerSection = lis.length;
}

for (var i=0; i<numSections; i++){
oUL = document.create Element('ul');

for (var j=0; j<numPerSection ; j++){
oUL.appendChild (lis[0]);
}

if (extras-- 0){
oUL.appendChild (lis[0]);
}
div.appendChild (oUL);
}
div.removeChild (ul);
}
--
Rob

Aug 25 '06 #3

David wrote:
Or basically, how can you split an array into spearate groups by dividing
the length of the array by 3. If the array has 15 entries, how can I grab 3
chunks of 5 out of the 15 ?
The algorithm is in my other reply to this thread:

1. Divide the number of items by the number of sections, the
result is the number per section - truncate any decimal part

2. If the number per section is less than 1, put all items in one
section.

3. Get numberOfItems modulo numberPerSectio n to find out what the
'remainder' is and distribute them evenly over the sections (put an
extra one on the first 'remainder' number of sections)
--
Rob

Aug 25 '06 #4
Yes Rob, that is exactly what I was trying to achieve. Many thanks. The
getElementById( ) was just a typo. I do know better than that :-)

Now to soak all in what you did... thanks bundles...

David J.


"RobG" <rg***@iinet.ne t.auwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
David wrote:
>Hello All,

I am trying to split a long list of list items ( li ) into 3 groups and
append them to a div on the page. Below is the test page that I have
created. It's fairly simple but I can't seem to get my head wrapped
around
it. Anyone here can offer a boost?

http://mysite.verizon.net/microweb2/3collist.html

In the line:
var container = document.getEle mentByID('write Me');

You have the wrong capitalisation for getElementById( )

I think what you are trying to do is divide the li elements evenly
between 3 ul elements. If so, you need to work out how many to put
into each ul, then do it. Rather than try to munge the script you have,
I'll just post the following script give you some pointers:

function quickTest()
{
var numSections = 3; // Number of sections
var numPerSection; // Number in each section (calculate)
var extras = 0; // Remainder if not equal number
// in all sections

var oUL; // New ul element
var div = document.getEle mentById('pCont ent');
var ul = div.getElements ByTagName('ul')[0];
var lis = ul.getElementsB yTagName('li');
var numPerSection = lis.length/numSections | 0;

if (numPerSection) {
extras = lis.length % numSections;
} else {
numPerSection = lis.length;
}

for (var i=0; i<numSections; i++){
oUL = document.create Element('ul');

for (var j=0; j<numPerSection ; j++){
oUL.appendChild (lis[0]);
}

if (extras-- 0){
oUL.appendChild (lis[0]);
}
div.appendChild (oUL);
}
div.removeChild (ul);
}
--
Rob

Aug 25 '06 #5
Can I ask you what this is?

var numPerSection = lis.length/numSections | 0;

I don't understand the pipe 0 part.

David

"David" <ri***@dd.comwr ote in message news:fnvHg.2074 3$Te.1332@trndd c07...
Yes Rob, that is exactly what I was trying to achieve. Many thanks. The
getElementById( ) was just a typo. I do know better than that :-)

Now to soak all in what you did... thanks bundles...

David J.


"RobG" <rg***@iinet.ne t.auwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
>David wrote:
>>Hello All,

I am trying to split a long list of list items ( li ) into 3 groups and
append them to a div on the page. Below is the test page that I have
created. It's fairly simple but I can't seem to get my head wrapped
around
it. Anyone here can offer a boost?

http://mysite.verizon.net/microweb2/3collist.html

In the line:
var container = document.getEle mentByID('write Me');

You have the wrong capitalisation for getElementById( )

I think what you are trying to do is divide the li elements evenly
between 3 ul elements. If so, you need to work out how many to put
into each ul, then do it. Rather than try to munge the script you have,
I'll just post the following script give you some pointers:

function quickTest()
{
var numSections = 3; // Number of sections
var numPerSection; // Number in each section (calculate)
var extras = 0; // Remainder if not equal number
// in all sections

var oUL; // New ul element
var div = document.getEle mentById('pCont ent');
var ul = div.getElements ByTagName('ul')[0];
var lis = ul.getElementsB yTagName('li');
var numPerSection = lis.length/numSections | 0;

if (numPerSection) {
extras = lis.length % numSections;
} else {
numPerSection = lis.length;
}

for (var i=0; i<numSections; i++){
oUL = document.create Element('ul');

for (var j=0; j<numPerSection ; j++){
oUL.appendChild (lis[0]);
}

if (extras-- 0){
oUL.appendChild (lis[0]);
}
div.appendChild (oUL);
}
div.removeChild (ul);
}
--
Rob


Aug 25 '06 #6
David wrote:
Can I ask you what this is?

var numPerSection = lis.length/numSections | 0;

I don't understand the pipe 0 part.
Please don't top post, reply below a trimmed quote.

'|' is a bit-wise OR operator which causes the first part of the
expression to be converted to an integer and truncated. It is the same
as:

var numPerSection = Math.floor( lis.length / numSections );
but shorter - some also say faster, but that is irrelevant here since
you have to do about 10,000 loops to notice.
--
Rob

Aug 25 '06 #7
'|' is a bit-wise OR operator which causes the first part of the
expression to be converted to an integer and truncated. It is the same
as:
var numPerSection = Math.floor( lis.length / numSections );

but shorter - some also say faster, but that is irrelevant here since
you have to do about 10,000 loops to notice.
Sorry about the top post and trim .. noted.

Thanks for your help and explanation(s)

David J.
Aug 25 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2130
by: Luka Milkovic | last post by:
Hello, I have a little problem and although it's little it's extremely difficult for me to describe it, but I'll try. I have written a program which extracts certain portions of my received e-mail. The content of the e-mail is actually predictable, it has one very long list of numbers, something looking like this:
5
3264
by: oliver | last post by:
hi there i'm experimanting with imaplib and came across stringts like (\HasNoChildren) "." "INBOX.Sent Items" in which the quotes are part of the string. now i try to convert this into a list. assume the string is in the variable f, then i tried f.split() but i end up with
3
2619
by: David Pratt | last post by:
Hi. I am splitting a string on a non whitespace character. One or more whitespace characters can be returned as items in the list. I do not want the items in the list that are only whitespace (can be one or more characters of whitespace) and plan to use string.strip on those items that are not only whitespace (to remove any whitespace from front or back of items). What kind of efficient test can I use to obtain only list items returned...
3
1517
by: Sambo | last post by:
I have couple of puzzles in my code. def load_headers( group_info ): if os.path.isfile( group_info.pointer_file ): ptr_file = open( group_info.pointer_file, "r" ) else: print group_info.mess_list return linecount = 0
1
11895
by: maxtoroq | last post by:
I know how to work the .FindAll method of the List class, but is there a way to split a list into 2 lists, one containing all the items that match a certain criteria and one that doesn't?
24
4819
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross multiple lines. It would appear though that every distinct set of data starts with a 'code' that is always the 25 characters long. The text is variable however. Assuming i've read the contents of the file into the string myfile, how do i split my...
1
4814
by: clayalphonso | last post by:
Here is the code: <% dim testArray, testArray2 dim Conn, rs dim sSQL, sConnString 'response.write request.form("sel1") 'testArray = split(request.form("sel1"),",") 'for each gidstuff In testArray 'Response.Write gidstuff & "<br />"
1
3620
by: Roy | last post by:
I have a table with two fields. I wish to separate all the data in one field and keep it listed against the information in the other field. The information within the field TicketStatus, I wish to separate is separated with a small box, meaning a tab .There can be up to twenty separate bits of info in the field. I would like to get a table in which the information in the field I am trying to separate (TicketStatus),is individually listed...
2
3748
by: Shawn Minisall | last post by:
I'm trying to unpack a list of 5 floats from a list read from a file and python is telling me 5 variables are too many for the string.split statement. Anyone have any other idea's? NOTE: the only reason I convert it to a float instead of just leaving it as a string in the loop is because I have to have it printed out as a float besides the names and then the average displayed underneath thx #read in data line by line
0
7969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7886
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1238
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.