Rotating content for table cells

R

Richard Cornford

RobB wrote:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">
<head>
var alldivs = document.getElementsByTagName('DIV');
<snip>

XHTML DOMs are case sensitive (like XHTML mark-up) and because the tag
and attribute names are all lowercase in the mark-up they are expected
to also be all lowercase when being referred to with scripts.

Additionally, the namespace qualified ('NS' prefixed) methods (when
available) produce more reliable results in XHTML DOMs.

Richard.
 
M

Michael Winter

JRS: In article <opsh9x9z1mx13kvk@atlantis>, dated Tue, 30 Nov 2004
10:59:52, seen in Michael Winter


Really?

Yes. If you want a document to be useful to the widest audience, you don't
make it rely upon scripting. Javascript *is* an optional technology and
too many people fail to realise that.
How about <URL:http://www.merlyn.demon.co.uk/astro.htm#Calc>, for
example? Or some of my other pages?

To me at least, your pages demonstrate method rather than provide means.
Furthermore, your pages have a fairly restricted scientific audience. If
you provided utilities to the general public, it would be a mistake (in my
opinion).
It's a mistake to assume that all javascript on the Web is for
transactions, or that all hosts offer programmable servers.

I haven't made that mistake, but in any case, to make the *entire* content
- which was the situation I was commenting on - dependent upon scripting
is stupid.

[snip]

Mike
 
G

Grant Wagner

Dr said:
JRS: In article <opsh9x9z1mx13kvk@atlantis>, dated Tue, 30 Nov 2004
10:59:52, seen in Michael Winter <M.Winter@bl
ueyonder.co.invalid> posted :


Really?
How about <URL:http://www.merlyn.demon.co.uk/astro.htm#Calc>, for
example? Or some of my other pages?

Those pages are badly designed because if client-side JavaScript is disabled, they
provide no functionality at all. If you really want people using your calculators,
and client-side JavaScript is disabled, then you should round-trip to the server to
do the calculation.
My pages are designed so that any CPU power used other than for sending
the page is supplied by the fetcher of the page.

And if the optional technology of client-side scripting is unavailable, then you
can not utilize the CPU power of the fetcher of the page, so you should supply your
own.
One could say that disabling javascript should never prevent some form
of display, and that that display should be designed and not merely
fortuitous. And that disabling javascript should not prevent
transactions.

I would consider a client-side scripted calculator a "transaction". If the
calculation can not be performed on the client, it should be sent to the server for
calculation and to display the result.


The original statement still stands, if you disagree with it, then perhaps your Web
site fits into the "controlled environment". A "controlled environment" which
includes the group of users who have client-side JavaScript enabled at all times,
and that client-side JavaScript supports all functionality required to carry out
the tasks you need performed.
 
R

royal_denning

McK, I really appreciate your help thus far, and I am learning (albeit
a bit slower than I would like) from your examples and suggestions.

I have a few more questions.

1. Going back to the rotate10 script (see below) you wrote, how would I
modify it to create a table with 1 column and 10 rows (instead of 2
columns with 5 rows). I would still want the cell contents to rotate
randomly.

2. I created a folder on the topsearchspot site called newpage folder,
and in that folder is a page called newpage.htm. On both versions of
the rotate10 script (1 and 2 columns) how would I add a RELATIVE link
so that the image is linked to /newpage folder/newpage.htm instead of
www.topsearchspot/newpage folder/newpage.htm?

Here is the script:

<html>
<head>
<title>rotate10.html</title>
<script type="text/javascript">
function numbers() {
var url = "http://www.topsearchspot.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|Three";
gif[4] = "4.gif|Four";
gif[5] = "5.gif|Five";
gif[6] = "6.gif|Six";
gif[7] = "7.gif|Seven";
gif[8] = "8.gif|Eight";
gif[9] = "9.gif|Nine";
for (var i=0; i<gif.length; i++) {
gif = url + gif;
}
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>

Thanks!
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Sat, 27 Nov 2004 13:25:51, seen in Royal
Denning said:
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.

It's not clear what you mean by "rotate randomly" - by what sort of
angle? True text cannot be rotated, and images can only be replaces by
ones of different orientation. And is the rotation by a random amount,
or after a random interval?

If your native tongue is one of the better-known ones from the western
parts of the Continent (i.e. mainland Europe), then it might help if you
were to post both in that and in English.
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).

Or do the contents of cells seem to move from one cell to another? Do
they occur in, and maintain, a natural sequence, following each other
round; or do they move from cell to cell randomly, similarly to a deck
of cards being shuffled?

The more effort that you put into explain9ing your wants with absolute
clarity, the more likely it is that you will be shown efficient and
relevant code.

The code in your article dated 2 Dec 2004 09:48:33 -0800 is badly laid
out - code should be indented to show its intended structure - and
unnecessarily complex. As a minor example,

src = "<a href='" + tmp[0] + "' target='_blank'>"
src += "<img src='" + tmp[0] + "'";
src += "border='0' width='" + wid + "' height='" + hig + "'

can be written as

src = "<a href='" + tmp[0] + "' target='_blank'>" +
"<img src='" + tmp[0] + "'" +
"border='0' width='" + wid + "' height='" + hig + "' ;

which uses fewer characters and is IMHO easier to read and slightly
faster.
 
R

Royal Denning

Hello, John. I am not only a native speaker of English, I've been paid
to write it professionally for most of my adult life.

If I was brief and informal it was because I didn't think anyone on
the newsgroup wanted to read a long, detailed message about what I
wanted (perhaps I was wrong in that, but that was my instinct). In any
case, McKirahan figured out what I was asking for easily enough, so I
don't think it was that unclear.

But I wouldn't mind reiterating what I was looking for originally.
What I was hoping for was a Javascript that would populate the cells
of an HTML table with images and text (and relative hyperlinks to
other pages on the site) from a folder on the website I'm working on.
Upon refreshing the page, the contents of the cells would shuffle
randomly. For a visual example of the shuffling process, see
http://www.topsearchspot.com/rotate10.htm.

McKirahan helpfully supplied a Javascript that built the table and
shuffled the cell contents accordingly, but given my limited knowledge
of Javascript, maybe it would be better to ask for a script that
populates the cells of a pre-built html table. Whichever would be
easier for someone with limited Jscript knowledge to customize.

Anyway, after some testing with McKirahan's scripts I've decided I
need a table with 2 columns and 5 rows (as seen on the link above) and
a table with 1 column and ten rows. I've decided to include the text
as part of the images now, so the script would just populate the cells
of the table with images and relative hyperlinks, and the contents of
the cells would randomly shuffle whenever the page reloads. I would
also like to be able to add rows to the tables and still have them
shuffle correctly as more images become available. (For example, I'd
like to have the flexibility to add an eleventh row to the ten-row
table when the time comes).

As noted before, I'm open to other scripts that will accomplish this
(although I really appreciate McKirahan's efforts on my behalf so
far).

If I was briedDr John Stockton said:
JRS: In article <[email protected]>, dated
Sat, 27 Nov 2004 13:25:51, seen in Royal
Denning said:
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.

It's not clear what you mean by "rotate randomly" - by what sort of
angle? True text cannot be rotated, and images can only be replaces by
ones of different orientation. And is the rotation by a random amount,
or after a random interval?

If your native tongue is one of the better-known ones from the western
parts of the Continent (i.e. mainland Europe), then it might help if you
were to post both in that and in English.
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).

Or do the contents of cells seem to move from one cell to another? Do
they occur in, and maintain, a natural sequence, following each other
round; or do they move from cell to cell randomly, similarly to a deck
of cards being shuffled?

The more effort that you put into explain9ing your wants with absolute
clarity, the more likely it is that you will be shown efficient and
relevant code.

The code in your article dated 2 Dec 2004 09:48:33 -0800 is badly laid
out - code should be indented to show its intended structure - and
unnecessarily complex. As a minor example,

src = "<a href='" + tmp[0] + "' target='_blank'>"
src += "<img src='" + tmp[0] + "'";
src += "border='0' width='" + wid + "' height='" + hig + "'

can be written as

src = "<a href='" + tmp[0] + "' target='_blank'>" +
"<img src='" + tmp[0] + "'" +
"border='0' width='" + wid + "' height='" + hig + "' ;

which uses fewer characters and is IMHO easier to read and slightly
faster.
 
R

RobB

Royal Denning wrote:

[snip]
As noted before, I'm open to other scripts that will accomplish this...

[snip]

Apparently not enough to bother reading them when they're offered... :(
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Fri, 3 Dec 2004 00:44:05, seen in Royal
Denning said:
I am not only a native speaker of English, I've been paid
to write it professionally for most of my adult life.

;-( So have most of those who write for the public media. The second
part of that paragraph proves nothing.

But I wouldn't mind reiterating what I was looking for originally.
What I was hoping for was a Javascript that would populate the cells
of an HTML table with images and text (and relative hyperlinks to
other pages on the site) from a folder on the website I'm working on.
Upon refreshing the page, the contents of the cells would shuffle
randomly. For a visual example of the shuffling process, see
http://www.topsearchspot.com/rotate10.htm.

Shuffling randomly is not rotating. Those of us who use off-line
newsreaders generally do not want to access the on-line Web to
understand a question that could have been fully explained in News.

... given my limited knowledge
of Javascript, maybe it would be better to ask for a script that
populates the cells of a pre-built html table.

That's not difficult; but it seems not worthwhile unless the table is to
be changed whilst it is being displayed.



Read the newsgroup FAQ - responses should go after trimmed quotes,
interleaved if addressing more than one point. That is the standard
Usenet recommendation.


You will also find in the FAQ an entry on Dealing and Shuffling

Aside: <FAQENTRY> That is not found by a search for "Shuffle" - I
suggest changing to "How to Deal and Shuffle" </FAQENTRY>

linking to http://www.merlyn.demon.co.uk/js-randm.htm - what you need is
a Deal of the numbers which refer to what goes in the cells.

The following will write such a Table; you will need to enhance the
function Put that generates the full content of a cell from its number,
q.

Note the use of a "standard" function for each "standard" task - Randum
& Deal - and for detail which is best moved out of its surroundings
(Put, Tabel) for clarity.

Note the use of function parameters, e.g. in Tabel.


function Randum(N) { return (N*(Math.random()%1))|0 }

function Deal(N) { var J, K, Q = new Array(N)
for (J=0; J<N; J++) { K = Randum(J+1) ; Q[J] = Q[K] ; Q[K] = J }
return Q }

function Put(q) { return "Thing<br>Number<br>" + q }

function Tabel(Rows, Cols) { var A = Deal(Rows*Cols), K=0, C, R
document.writeln("<table border=1>")
for (R=0;R<Rows;R++) { document.writeln("<tr>")
for (C=0;C<Cols;C++) document.writeln("<td>", Put(A[K++]), "<\/td>")
document.writeln("<\/tr>") }
document.writeln("<\/table>") }

Tabel(3, 5)


Tested in <URL:http://www.merlyn.demon.co.uk/js-quick.htm>.
 
R

Royal Denning

Apologies, Rob. I must have clicked past your script by accident. I
will give it a try.

Thanks.

Royal Denning wrote:

[snip]
As noted before, I'm open to other scripts that will accomplish this...

[snip]

Apparently not enough to bother reading them when they're offered... :(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top