473,722 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rotating content for table cells

I am designing a table with 2 columns and 20 rows. I want to insert
small images (each with a link) and a text title in each cell of the
table.

On refresh of the page, I would like to have the contents of each cell
(picture/link and associated text) rotate randomly.

Note that the text titles must remain with their associated picture
and link (I don't want to scramble all the elements--just rotate the
entire contents of the table cell).

Is there a script that will accomplish this? Thanks.
Jul 23 '05 #1
31 7029
"Royal Denning" <ro***********@ hotmail.com> wrote in message
news:4e******** *************** **@posting.goog le.com...
I am designing a table with 2 columns and 20 rows. I want to insert
small images (each with a link) and a text title in each cell of the
table.

On refresh of the page, I would like to have the contents of each cell
(picture/link and associated text) rotate randomly.

Note that the text titles must remain with their associated picture
and link (I don't want to scramble all the elements--just rotate the
entire contents of the table cell).

Is there a script that will accomplish this? Thanks.


Perhaps this will give you some ideas.

Test "as is"; watch for word-wrap.

<html>
<head>
<title>rotate26 .htm</title>
<script type="text/javascript">
function letters() {
var abc = "abcdefghijklmn opqrstuvwxyz";
var now = new Date();
var pos = now.getSeconds( )%26;
var let = abc.substr(pos) ;
if (pos > 0) let += abc.substring(0 ,pos);
alert(pos + "\t" + let);
var url = "http://205.200.38.172/aagraphics/letters/letter?.jpg";
var src;
var txt = new Array();
var img = new Array();
for (var i=0; i<let.length; i++) {
src = "<a href='" + url + "' target='_blank' >"
src += "<img src='" + url + "'";
src += "border='0' width='109' height='83' alt='?'></a>";
img[i] = src.replace(/\?/g,let.charAt(i) );
txt[i] = "<br>The Letter " + let.charAt(i).t oUpperCase();
}
var j = 0;
var tab = new Array();
tab[j++] = "<table border='0' cellpadding='0' cellspacing='0'
width='218'>";
var mid = let.length/2;
for (var k=0; k<mid; k++) {
tab[j++] = "<tr height='100' valign='top'>";
tab[j++] = " <th width='109'>" + img[k] + txt[k] + "</th>";
tab[j++] = " <th width='109'>" + img[k+mid] + txt[k+mid] +
"</th>";
tab[j++] = "</tr>";
}
tab[j++] = "</table>";
document.write( tab.join(""));
}
letters();
</script>
</head>
<body>
</body>
</html>
Jul 23 '05 #2
Thanks, McKirahan.

I'm still a bit of a newbie at Javascripting, so where do I enter the
values for the cells, images, text and urls?"
Jul 23 '05 #3
"Royal Denning" <ro***********@ hotmail.com> wrote in message
news:4e******** *************** ***@posting.goo gle.com...
Thanks, McKirahan.

I'm still a bit of a newbie at Javascripting, so where do I enter the
values for the cells, images, text and urls?"


This should be a little clearer.

<html>
<head>
<title>rotate10 .htm</title>
<script type="text/javascript">
function numbers() {
var url = "http://www.scri8e.com/TTF/alphas/redgelharts/";
var gif = new Array();
gif[0] = "0.gif|Zero ";
gif[1] = "1.gif|One" ;
gif[2] = "2.gif|Two" ;
gif[3] = "3.gif|Thre e";
gif[4] = "4.gif|Four ";
gif[5] = "5.gif|Five ";
gif[6] = "6.gif|Six" ;
gif[7] = "7.gif|Seve n";
gif[8] = "8.gif|Eigh t";
gif[9] = "9.gif|Nine ";
for (var i=0; i<gif.length; i++) {
gif[i] = url + gif[i];
}
var hig = 82;
var wid = 46;
var wyd = wid*2;
var ten = "0123456789 ";
var mod = ten.length;
var now = new Date();
var pos = now.getSeconds( )%mod;
var num = ten.substr(pos) ;
if (pos > 0) num += ten.substring(0 ,pos);
var col = new Array();
var src;
var sub;
var tmp;
for (var j=0; j<num.length; j++) {
sub = num.charAt(j);
tmp = gif[sub].split("|");
src = "<a href='" + tmp[0] + "' target='_blank' >"
src += "<img src='" + tmp[0] + "'";
src += "border='0' width='" + wid + "' height='" + hig + "'
alt=''></a>";
src += "<br>" + tmp[1];
col[j] = src;
}
var k = 0;
var tab = new Array();
tab[k++] = "<table border='0' cellpadding='0' cellspacing='0'
width='" + wyd + "'>";
var mid = num.length/2;
for (var l=0; l<mid; l++) {
tab[k++] = "<tr height='" + hig + "' valign='top'>";
tab[k++] = " <th width='" + wid + "'>" + col[l] + "</th>";
tab[k++] = " <th width='" + wid + "'>" + col[l+mid] + "</th>";
tab[k++] = "</tr>";
}
tab[k++] = "</table>";
document.write( tab.join(""));
}
numbers();
</script>
</head>
<body>
</body>
</html>

Modify the "gif" array to identify each image followed by a "|" followed by
the text for the image. Change "wid" and "hig" to the "width" and "height"
of the images. This will handle rotating ten images; I'll leave it toyou to
handle twenty.
Jul 23 '05 #4
I tried the revised script on a test page and it doesn't seem to be
working. Here is the page in question:

http://www.topsearchspot.com/rotate10.htm

"Royal Denning" <ro***********@ hotmail.com> wrote in message
news:4e******** *************** ***@posting.goo gle.com...
Thanks, McKirahan.

I'm still a bit of a newbie at Javascripting, so where do I enter the
values for the cells, images, text and urls?"


This should be a little clearer.

Jul 23 '05 #5
"Royal Denning" <ro***********@ hotmail.com> wrote in message
news:4e******** *************** ***@posting.goo gle.com...
I tried the revised script on a test page and it doesn't seem to be
working. Here is the page in question:

http://www.topsearchspot.com/rotate10.htm

"Royal Denning" <ro***********@ hotmail.com> wrote in message
news:4e******** *************** ***@posting.goo gle.com...
Thanks, McKirahan.

I'm still a bit of a newbie at Javascripting, so where do I enter the
values for the cells, images, text and urls?"


This should be a little clearer.


Why did you add this?

<table width="62" border="0" height="62">
<tr>
<td><img src="0.gif" width="62" height="62"></td>
<td><img src="1.gif" width="62" height="62"></td>
</tr>
<tr>
<td><img src="2.gif" width="62" height="62"></td>
<td><img src="3.gif" width="62" height="62"></td>
</tr>
<tr>
<td><img src="4.gif" width="62" height="62"></td>
<td><img src="5.gif" width="62" height="62"></td>
</tr>
<tr>
<td><img src="6.gif" width="62" height="62"></td>
<td><img src="7.gif" width="62" height="62"></td>
</tr>
<tr>
<td><img src="8.gif" width="62" height="62"></td>
<td><img src="9.gif" width="62" height="62"></td>
</tr>
</table>

The script generates the table.
Jul 23 '05 #6
"McKirahan" <Ne**@McKirahan .com> wrote in message
news:5Tvqd.6825 63$8_6.324108@a ttbi_s04...
"Royal Denning" <ro***********@ hotmail.com> wrote in message
news:4e******** *************** ***@posting.goo gle.com...
I tried the revised script on a test page and it doesn't seem to be
working. Here is the page in question:

http://www.topsearchspot.com/rotate10.htm

"Royal Denning" <ro***********@ hotmail.com> wrote in message
news:4e******** *************** ***@posting.goo gle.com...
> Thanks, McKirahan.
>
> I'm still a bit of a newbie at Javascripting, so where do I enter the > values for the cells, images, text and urls?"

This should be a little clearer.


Why did you add this?

<table width="62" border="0" height="62">
<tr>
<td><img src="0.gif" width="62" height="62"></td>
<td><img src="1.gif" width="62" height="62"></td>
</tr>
<tr>
<td><img src="2.gif" width="62" height="62"></td>
<td><img src="3.gif" width="62" height="62"></td>
</tr>
<tr>
<td><img src="4.gif" width="62" height="62"></td>
<td><img src="5.gif" width="62" height="62"></td>
</tr>
<tr>
<td><img src="6.gif" width="62" height="62"></td>
<td><img src="7.gif" width="62" height="62"></td>
</tr>
<tr>
<td><img src="8.gif" width="62" height="62"></td>
<td><img src="9.gif" width="62" height="62"></td>
</tr>
</table>

The script generates the table.


Your version of the script did not work because of the line:
src += "border='0' width='"62"' height='"62"' alt=''></a>";
which should be
src += "border='0' width='" + wid + "' height='" + hig + "'
alt=''></a>";

Also, you had two <title> tags.

Try this:

<html>
<head>
<title>rotate10 .html</title>
<script type="text/javascript">
function numbers() {
var url = "http://www.topsearchsp ot.com/";
var gif = new Array(10);
gif[0] = "0.gif|Zero ";
gif[1] = "1.gif|One" ;
gif[2] = "2.gif|Two" ;
gif[3] = "3.gif|Thre e";
gif[4] = "4.gif|Four ";
gif[5] = "5.gif|Five ";
gif[6] = "6.gif|Six" ;
gif[7] = "7.gif|Seve n";
gif[8] = "8.gif|Eigh t";
gif[9] = "9.gif|Nine ";
for (var i=0; i<gif.length; i++) {
gif[i] = url + gif[i];
}
var hig = 62;
var wid = 62;
var wyd = wid*2;
var ten = "0123456789 ";
var mod = ten.length;
var now = new Date();
var pos = now.getSeconds( )%mod;
var num = ten.substr(pos) ;
if (pos > 0) num += ten.substring(0 ,pos);
var col = new Array();
var src;
var sub;
var tmp;
for (var j=0; j<num.length; j++) {
sub = num.charAt(j);
tmp = gif[sub].split("|");
src = "<a href='" + tmp[0] + "' target='_blank' >"
src += "<img src='" + tmp[0] + "'";
src += "border='0' width='" + wid + "' height='" + hig + "'
alt=''></a>";
src += "<br>" + tmp[1];
col[j] = src;
}
var k = 0;
var tab = new Array();
tab[k++] = "<table border='0' cellpadding='0' cellspacing='0'
width='" + wyd + "'>";
var mid = num.length/2;
for (var l=0; l<mid; l++) {
tab[k++] = "<tr height='" + 62 + "' valign='top'>";
tab[k++] = " <th width='" + 62 + "'>" + col[l] + "</th>";
tab[k++] = " <th width='" + 62 + "'>" + col[l+mid] + "</th>";
tab[k++] = "</tr>";
}
tab[k++] = "</table>";
document.write( tab.join(""));
}
numbers();
</script>
</head>
<body>
</body>
</html>
Jul 23 '05 #7
McK: It worked! Thanks so much.

My only remaining questions:

How do I plug in the separate URLS (relative links, such at one.htm,
two.htm, etc.) to each image,

and can I use the same script twice on a page (using different array
values, such at 11-20?

I really appreciate your patience and guidance on this.
Jul 23 '05 #8
"Royal Denning" <ro***********@ hotmail.com> wrote in message
news:4e******** *************** ***@posting.goo gle.com...
McK: It worked! Thanks so much.

My only remaining questions:

How do I plug in the separate URLS (relative links, such at one.htm,
two.htm, etc.) to each image,

and can I use the same script twice on a page (using different array
values, such at 11-20?

I really appreciate your patience and guidance on this.


Not the most elegant code ....

<html>
<head>
<title>rotate20 .htm</title>
<script type="text/javascript">
function numbers() {
var url = "http://www.topsearchsp ot.com/";
var gif = new Array(10);
// gif[#] = image | text | page
gif[0] = "0.gif|Zero|www .Google.com?00" ;
gif[1] = "1.gif|One|www. Google.com?01";
gif[2] = "2.gif|Two|www. Google.com?02";
gif[3] = "3.gif|Three|ww w.Google.com?03 ";
gif[4] = "4.gif|Four|www .Google.com?04" ;
gif[5] = "5.gif|Five|www .Google.com?05" ;
gif[6] = "6.gif|Six|www. Google.com?06";
gif[7] = "7.gif|Seven|ww w.Google.com?07 ";
gif[8] = "8.gif|Eight|ww w.Google.com?08 ";
gif[9] = "9.gif|Nine|www .Google.com?09" ;
gif[10] = "0.gif|Ten|www. Google.com?10";
gif[11] = "1.gif|Eleven|w ww.Google.com?1 1";
gif[12] = "2.gif|Twelve|w ww.Google.com?1 2";
gif[13] = "3.gif|Thirteen |www.Google.com ?13";
gif[14] = "4.gif|Fourteen |www.Google.com ?14";
gif[15] = "5.gif|Fifteen| www.Google.com? 15";
gif[16] = "6.gif|Sixteen| www.Google.com? 16";
gif[17] = "7.gif|Seventee n|www.Google.co m?17";
gif[18] = "8.gif|Eighteen |www.Google.com ?18";
gif[19] = "9.gif|Nineteen |www.Google.com ?19";
for (var i=0; i<gif.length; i++) {
gif[i] = url + gif[i];
}
var hig = 62;
var wid = 62;
// Change values above but not below.
var wyd = wid*2;
var xix = "00010203040506 070809101112131 41516171819";
var mod = xix.length/2;
var now = new Date();
var pos = now.getSeconds( )%mod;
var num = xix.substr(pos* 2-2);
if (pos > 0) num += xix.substring(0 ,pos*2-2);
var col = new Array();
var src;
var sub;
var tmp;
var k = 0;
for (var j=0; j<num.length; j++) {
sub = parseInt(num.su bstring(j,j+2), 10);
tmp = gif[sub].split("|");
src = "<a href='http://" + tmp[2] + "' target='_blank' >"
src += "<img src='" + tmp[0] + "'";
src += "border='0' width='" + wid + "' height='" + hig + "'
alt=''></a>";
src += "<br>" + tmp[1];
col[k] = src;
j++;
k++;
}
var l = 0;
var tab = new Array();
tab[l++] = "<table border='0' cellpadding='0' cellspacing='0'
width='" + wyd + "'>";
var mid = num.length/4;
for (var m=0; m<mid; m++) {
tab[l++] = "<tr height='" + hig + "' valign='top'>";
tab[l++] = " <th width='" + wid + "'>" + col[m] + "</th>";
tab[l++] = " <th width='" + wid + "'>" + col[m+mid] + "</th>";
tab[l++] = "</tr>";
}
tab[l++] = "</table>";
document.write( tab.join(""));
}
numbers();
</script>
</head>
<body>
</body>
</html>

The twenty "gif" entries (0 - 19) contain three elements seperated by "|"
are the image name ("0.gif"), the text (e.g. "One"), and the page (e.g.
www.Google.com?01 -- the "http://" is prepended later). The page can be any
valid url; for example, "www.Google .com/index.html".

Change the "gif" array as well as "url", "wid", and "hig" to suit your
needs. This presumes that all images are in the same folder specified by
the "url" and that all images are the same width ("wid") and height ("hig").
Jul 23 '05 #9
JRS: In article <Nzwqd.160663$H A.32847@attbi_s 01>, dated Mon, 29 Nov
2004 03:20:18, seen in news:comp.lang. javascript, McKirahan
<Ne**@McKirahan .com> posted :
function numbers() {
var url = "http://www.topsearchsp ot.com/";
var gif = new Array(10);
gif[0] = "0.gif|Zero ";
gif[1] = "1.gif|One" ;
gif[2] = "2.gif|Two" ;
gif[3] = "3.gif|Thre e";
gif[4] = "4.gif|Four ";
gif[5] = "5.gif|Five ";
gif[6] = "6.gif|Six" ;
gif[7] = "7.gif|Seve n";
gif[8] = "8.gif|Eigh t";
gif[9] = "9.gif|Nine ";
for (var i=0; i<gif.length; i++) {
gif[i] = url + gif[i];
}


Only a list of the names of the digits is needed; javascript can
assemble the rest when needed.

var Digits = ["Zero", ..., "Nine"] // is simpler.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #10

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

Similar topics

6
7724
by: Finn Newick | last post by:
By defining a style as follows: @media aural, handheld {td.layout {display:block;}} I'm hoping to linearise layout tables when viewed by screenreaders and handheld devices (it is also be in some selectable user preferences). This works as intended in Netscape 7 - all the cells stack vertically above each other nicely, but not in Internet Explorer 6 where the only display property that td will respond to seems to be 'none'.
8
4413
by: Jukka K. Korpela | last post by:
I just noticed that most browsers render <table border="1"><tr><td><p>foo</p></td></tr></table> the same way as <table border="1"><tr><td>foo</td></tr></table> That is, they ignore the p markup in the sense that they don't apply the normal default top and bottom margins. This is rather odd, especially
1
2642
by: Mark Carroll | last post by:
I can't get my table cells to not have a gap between them in IE. For example, with IE6SP1 I get a gap between the two red squares on http://www.chiark.greenend.org.uk/~markc/test/test.html instead of just seeing one red rectangle. The CSS in that case had width: 1px; margin: 0; padding: 0; border-width: 0; border-spacing: 0 What can I do to get the red squares nestled together in the table with no space in between? -- Mark
4
26208
by: N. Demos | last post by:
The following code renders as intended in IE (A TABLE, with cells of fixed width and height, inside of a DIV with fixed width and height and overflow set to hidden.) In Firefox, the table cells assume a narrower with than specified. If I comment out the width for the DIV, then the cells render with the correct width and height. Why is this happening? Thanks. Regards, N. Demos
0
1684
by: N. Demos | last post by:
I have a single row table with fixed dimensioned cells nested inside a fixed dimensioned div, which has overflow: hidden. The div's dimensions are such that It should only display the first two table cells. This all renders correctly in MSIE 6.x, but doesn't in Firefox. In Firefox, the cell widths are reduced so that all the cells are displayed within the div frame. I've played around with this: commenting out css properties to see if...
3
5909
by: N. Demos | last post by:
I have a single row table with fixed dimensioned cells nested inside a fixed dimensioned div, which has overflow: hidden. The div's dimensions are such that It should only display the first two table cells. This all renders correctly in MSIE 6.x, but doesn't in Firefox. In Firefox, the cell widths are reduced so that all the cells are displayed within the div frame. I've played around with this: commenting out css properties to see if...
5
36876
by: Richard Dixson | last post by:
I created a new C# web application. Basically all I am trying to do is create a table that consists of a few rows with two columns in each. And then to set those columns to text values from my code behind. However I am not able to do this at all, I am going about this wrong, I think and need guideance. If this was just straight HTML I would do this: <table> <tr><td>field 1</td><td>value 1 set by code behind</td></tr>
1
2915
by: RobG | last post by:
I'm trying to get table cells to clip content rather than wrapping. It has been suggested to use: td.clipped { width: 5em; overflow: hidden; white-space: nowrap; }
0
1323
by: JM | last post by:
I'm using VS2005 SP1. It seems to me, when I used VS2003, the IDE would only insert height and width attributes in table cells if you dragged to resize a cell. Now, with VS2005, I get the style attributes whenever I drop a control into a cell or add content, and it's ANNOYING. Does anybody know of a way to get designer to stop slapping style attributes in table cells?
2
3029
by: markszlazak | last post by:
I'm a relatively slow response of table cells changing their background color with mouseover/our in IE6 (Win 2K) but the response is fine (fast) in Firefox. Why? The code is below. Sorry about the length. <html> <head> <title>Rapid Blocking Interface</title> <style> .calendar {
0
8860
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
9381
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
9234
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...
1
9151
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6680
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
4501
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...
2
2600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2146
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.