Generated cells in HTML table not showing

S

SandyTipper

I thought this was a trivial bit of code, but it doesn't seem to work.
Anybody wlling to help?
I create a simple one-row html table, and insert a javascript piece
between the <tr> and </tr>, which should use document.write to
create three columns to display random ads for my site's sponsors.

<P align=center>
<TABLE style="BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px
solid; MARGIN: 1px; BORDER-COLLAPSE: collapse; BORDER-TOP: #999999 1px
solid; BORDER-RIGHT: #999999 1px solid" class=contStyleExcSimpleTable
cellSpacing=0 cellPadding=3 width="97%" bgColor=#ffffff align=left>
<TBODY>
<TR><script type="text/javascript">
var myAds=[]; //will contain the ads

// Edit here: Put the cell contents in myAds elements

myAds[0]='<H3>Hair Spa</H3><blockquote>ad content</blockquote>';
myAds[1]='<H3>This Space for Rent</H3>';
myAds[2]='<H3>Ads: $35/year</H3>';
myAds[3]='<H3>Your Ad Here</H3>';

// End of editing
var myCell=[]; // random indexes into myAds; 3 elements
myCell[0]=Math.floor(Math.random()*myAds.length);
do {
myCell[1]=Math.floor(Math.random()*myAds.length);
} while (myAds.length > 2 && myCell[1] != myCell[0]);
do {
myCell[2]=Math.floor(Math.random()*myAds.length);
} while (myAds.length > 2 && myCell[2] != myCell[0] && myCell[2] !=
myCell[1]);

for (var i=0; i<3; i++){
document.write('<TD style="width: 33%;VERTICAL-ALIGN: top;">';
document.write(myAds[myCell]);
document.write('</TD>');
}
</script></TR></TBODY></TABLE></P>
 
S

SandyTipper

SandyTipper said:
I thought this was a trivial bit of code, but it doesn't seem to work.
Anybody wlling to help?
I create a simple one-row html table, and insert a javascript piece
between the <tr> and </tr>, which should use document.write to
create three columns to display random ads for my site's sponsors.

<P align=center>
<TABLE style="BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px
solid; MARGIN: 1px; BORDER-COLLAPSE: collapse; BORDER-TOP: #999999 1px
solid; BORDER-RIGHT: #999999 1px solid" class=contStyleExcSimpleTable
cellSpacing=0 cellPadding=3 width="97%" bgColor=#ffffff align=left>
<TBODY>
<TR><script type="text/javascript">
var myAds=[]; //will contain the ads

// Edit here: Put the cell contents in myAds elements

myAds[0]='<H3>Hair Spa</H3><blockquote>ad content</blockquote>';
myAds[1]='<H3>This Space for Rent</H3>';
myAds[2]='<H3>Ads: $35/year</H3>';
myAds[3]='<H3>Your Ad Here</H3>';

// End of editing
var myCell=[]; // random indexes into myAds; 3 elements
myCell[0]=Math.floor(Math.random()*myAds.length);
do {
myCell[1]=Math.floor(Math.random()*myAds.length);
} while (myAds.length > 2 && myCell[1] != myCell[0]);
do {
myCell[2]=Math.floor(Math.random()*myAds.length);
} while (myAds.length > 2 && myCell[2] != myCell[0] && myCell[2] !=
myCell[1]);

for (var i=0; i<3; i++){
document.write('<TD style="width: 33%;VERTICAL-ALIGN: top;">';
document.write(myAds[myCell]);
document.write('</TD>');
}
</script></TR></TBODY></TABLE></P>

Oh, yes, if you're wondering why I didn't do this server-side so it
does not depend on clients permitting javascript, I can't. Not my server.
 
L

Luuk

SandyTipper schreef:
so, you want to make money with your website...?
........
yCell[1]);
for (var i=0; i<3; i++){
document.write('<TD style="width: 33%;VERTICAL-ALIGN: top;">';


and you cannot even count if you have every '(' properly closed with a
')'....
document.write(myAds[myCell]);
document.write('</TD>');
}
</script></TR></TBODY></TABLE></P>

Oh, yes, if you're wondering why I didn't do this server-side so it
does not depend on clients permitting javascript, I can't. Not my server.


and all that 'claiming' that is not your server.....
What is the difference that its yours, or not?
 
C

Captain Paralytic

I thought this was a trivial bit of code, but it doesn't seem to work.
Anybody wlling to help?
I create a simple one-row html table, and insert a javascript piece
between the <tr> and </tr>, which should use document.write to
create three columns to display random ads for my site's sponsors.

<P align=center>
<TABLE style="BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px
solid; MARGIN: 1px; BORDER-COLLAPSE: collapse; BORDER-TOP: #999999 1px
solid; BORDER-RIGHT: #999999 1px solid" class=contStyleExcSimpleTable
cellSpacing=0 cellPadding=3 width="97%" bgColor=#ffffff align=left>
<TBODY>
<TR><script type="text/javascript">
var myAds=[]; //will contain the ads

// Edit here: Put the cell contents in myAds elements

myAds[0]='<H3>Hair Spa</H3><blockquote>ad content</blockquote>';
myAds[1]='<H3>This Space for Rent</H3>';
myAds[2]='<H3>Ads: $35/year</H3>';
myAds[3]='<H3>Your Ad Here</H3>';

// End of editing
var myCell=[]; // random indexes into myAds; 3 elements
myCell[0]=Math.floor(Math.random()*myAds.length);
do {
  myCell[1]=Math.floor(Math.random()*myAds.length);} while (myAds.length > 2 && myCell[1] != myCell[0]);

do {
  myCell[2]=Math.floor(Math.random()*myAds.length);} while (myAds.length > 2 && myCell[2] != myCell[0] && myCell[2] !=

myCell[1]);

for (var i=0; i<3; i++){
  document.write('<TD style="width: 33%;VERTICAL-ALIGN: top;">';
  document.write(myAds[myCell]);
  document.write('</TD>');}

</script></TR></TBODY></TABLE></P>


Just a few observations:
1) "it doesn't seem to work" is as useful as a chocolate teapot. A
description of what does happen and/or what error messages you get is
far more helpful.
2) explaining what you have done to try to find out what is wrong is
also helpful.

Running it in either FireFox (and looking at the error console) or IE8
(with the developer tools switched on) reveals a syntax error sraight
away.
 
S

SandyTipper

Luuk said:
SandyTipper schreef:

so, you want to make money with your website...?
No, it's a volunteer organization and we want to offset the cost of hosting.
and all that 'claiming' that is not your server.....
What is the difference that its yours, or not?
I don't care for your snippy tone, but I don't have admin rights,
and the hosting service doesn't permit server-side scripting.
 
D

Doug Miller

No, it's a volunteer organization and we want to offset the cost of hosting.
I don't care for your snippy tone, but I don't have admin rights,
and the hosting service doesn't permit server-side scripting.

Then move the domain to a better hosting service. The one you have now is
worthless.
 
S

SandyTipper

I thought this was a trivial bit of code, but it doesn't seem to work.
Anybody wlling to help?
I create a simple one-row html table, and insert a javascript piece
between the <tr> and </tr>, which should use document.write to
create three columns to display random ads for my site's sponsors. ....
document.write('<TD style="width: 33%;VERTICAL-ALIGN: top;">';
....

Just a few observations:
1) "it doesn't seem to work" is as useful as a chocolate teapot. A
description of what does happen and/or what error messages you get is
far more helpful.
2) explaining what you have done to try to find out what is wrong is
also helpful.

Running it in either FireFox (and looking at the error console) or IE8
(with the developer tools switched on) reveals a syntax error sraight
away.
 
D

Dr J R Stockton

Wed said:
I thought this was a trivial bit of code, but it doesn't seem to work.
Anybody wlling to help?

You should say in what way it does not work.

I create a simple one-row html table, and insert a javascript piece
between the <tr> and </tr>, which should use document.write to
create three columns to display random ads for my site's sponsors.



You should, before posting, remorselessly remove from the code all that
is not necessary to demonstrate the not-working. Then test what's left;
it may now work. You can, for example, remove all style; then we do not
have to read it.

Repeated code , such as
Math.floor(Math.random()*myAds.length)
should be put into a function Random, as in the FAQ, which you ought to
have read.

You know of the missing ).
The first "2 &&" should be clearly "1 &&".

Your logic is wrong; each != should be == , the last && should be ||,
and you should consider whether that then needs more parentheses.



Your algorithm is cumbersome. Your selection problem is equivalent to
drawing three ads from a deck of four ads, which is like dealing, and
reading the FAQ will lead you to what you need there.

Deal(myAds.length) will generate a list of all ad indexes in random
order :

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

and you just take what you need. For a vast number of ads it would be
better to generate a partial list only; you now should be able to find
code for that.
 

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

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top