Menu
Would some kind person know of a script that, imbedded in a web page, will take a <ul> list of items and display them in a 2 or three-column <table>?
Thanks.
[code=php]
<table border=1>
<tr><td>
<ul>
<li>List 1 item 1</li>
<li>List 1 item 2</li>
<li>List 1 item 3</li>
<ul>
</td><td>
<ul>
<li>List 2 item 1</li>
<li>List 2 item 2</li>
<li>List 2 item 3</li>
<ul>
</td><td>
<ul>
<li>List 3 item 1</li>
<li>List 3 item 2</li>
<li>List 3 item 3</li>
<ul>
</td><tr>
</table>
[/code]
Unless you want to use <DIV> and CSS coding.Why not this?
<static table snipped>[/quote]
[code=php]
Col1List = new Array(
'List 1 - Item 1',
'List 1 - Item 2',
'List 1 - Item 3');
[/code]
[code=php]
<table border=1><tr>
<script type="text/javascript">
var str = '<td><ul>';
for (items=0; items<Col1List.length; items++) {
str += '<li>'+Col1List[items]+'</li>';
}
document.write(str);
// repeat as needed for other columns
</script>
</tr></table>
[/code]
<i>
</i> <script type="text/javascript">
<!-- Hide this code from non-JavaScript browsers
MC_ncol=5; // number of columns
MC_list=new Array( // items in the list
'item 1',
'item 2',
'item 3',
'item 4',
'item 5',
'item 6',
'item 7',
'item 8',
'item 9',
'item 10',
'item 11',
'item 12',
'item 13',
'item 14',
'' // leave this alone
);
MC_nrow=Math.ceil((MC_list.length-1)/MC_ncol);
document.write('<table border="1" cellspacing="2" cellpadding="2">n<tbody>n');
document.write('<tr>n<td valign="top">n');
for (MC_ix1=0; MC_ix1<MC_list.length-1; MC_ix1++) {
MC_item=MC_list[MC_ix1];
if (MC_ix1%MC_nrow == 0) {
if (MC_ix1 > 0) {
document.write('</td>n<td valign="top">n');
}
} else {
document.write('<br>n');
}
document.write(MC_ix1+': '+MC_item);
}
document.write('</td>n</tr>n</tbody>n</table>n');
// End hiding -->
</script>
Neat example 'jalarie'. Nice touch with the 'MC_ncol' variable.
'juanwei26' should find it easy to modify.[/QUOTE]
If he had a clue!! ? I'll give it a try and let you know what happens. Many thanks.[/QUOTE]That worked out pretty well.
[code=php]
<html>
<head>
<title>Multi-Column List</title>
</head>
<body>
<script type="text/javascript">
<!-- Hide this code from non-JavaScript browsers
MC_ncol=3; // number of columns
MC_list=new Array( // items in the list
'<a href="#ac">Air Conditioning/Heating</a>',
'<a href="#limo">Airport Transportation</a>',
'<a href="#sneeze">Allergist</a>',
'<a href="#appliance">Appliance Repair</a>',
'<a href="#bodyshop">Auto Body Shop</a>',
'' // leave this alone
);
MC_nrow=Math.ceil((MC_list.length-1)/MC_ncol);
document.write('<table border="1" cellspacing="2" cellpadding="2">n<tbody>n');
document.write('<tr>n<td valign="top">n');
for (MC_ix1=0; MC_ix1<MC_list.length-1; MC_ix1++) {
MC_item=MC_list[MC_ix1];
if (MC_ix1%MC_nrow == 0) {
if (MC_ix1 > 0) {
document.write('</td>n<td valign="top">n');
}
} else {
document.write('<br>n');
}
// document.write(MC_ix1+': '+MC_item);
document.write(MC_item);
}
document.write('</td>n</tr>n</tbody>n</table>n');
// End hiding -->
</script>
</body>
</html>
[/code]
[code=php]
// MC_list stored in 'MC_list.js' file
var MC_list = new Array (
'<li><a href="#ac">Air Conditioning/Heating</a> </li>',
'<li><a href="#limo">Airport Transportation</a></li>',
'<li><a href="#sneeze">Allergist</a></li>',
'<li><a href="#appliance">Appliance Repair</a></li>',
'<li><a href="#bodyshop">Auto Body Shop</a></li>',
'<li><a href="#goodwrench">Auto Service</a></li>',
'<li><a href="#awnings">Awnings</a></li>',
'<li><a href="#heart">Cardiologist</a></li>',
'<li><a href="#rug">Carpet Cleaning</a></li>',
'<li><a href="#tile">Ceramic Tile</a> </li>',
'<li><a href="#sweep">Chimney Sweep </a></li>',
'<li><a href="#cracker">Chiropractor</a></li>',
'<li><a href="#compudoc">Computer Service</a></li>',
'<li><a href="#copy">Copies, Printing, Graphic Design</a></li>',
'<li><a href="#cpa">CPA</a></li>',
'<li><a href="#dentist">Dentist</a></li>',
'<li><a href="#skin">Dermatologist</a></li>',
'<li><a href="#tar">Driveway Sealer</a></li>',
'<li><a href="#duct">Duct Cleaning</a></li>',
''); // leave blank
// enter where ever you want or alphabetical order
[/code]
[code=php]
<html>
<head>
<title>Multi-Column List</title>
<script type="text/javascript" src="MC_list.js"></script>
</head>
<body>
<script type="text/javascript">
<!-- Hide this code from non-JavaScript browsers
MC_ncol=5; // number of columns
MC_nrow=Math.ceil((MC_list.length-1)/MC_ncol);
document.write('<table border="1" cellspacing="2" cellpadding="2">n<tbody>n');
document.write('<tr>n<td valign="top"><ul>n');
for (MC_ix1=0; MC_ix1<MC_list.length-1; MC_ix1++) {
MC_item = MC_list[MC_ix1];
if (MC_ix1%MC_nrow == 0) {
if (MC_ix1 > 0) { document.write('</td>n<td valign="top">n'); }
} else { document.write('n'); }
document.write(MC_item);
}
document.write('</ul></td>n</tr>n</tbody>n</table>n');
// End hiding -->
</script>
</body>
</html>
[/code]
You program so its your choice.
I don't have either program, so I just do it the 'hard' way as 'easy' as I can.
Good luck with your endeavors.[/QUOTE]
0.1.9 — BETA 5.20