Generated cells in HTML table not showing

Discussion in 'Javascript' started by SandyTipper, Aug 12, 2009.

  1. SandyTipper

    SandyTipper Guest

    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>
    SandyTipper, Aug 12, 2009
    #1
    1. Advertising

  2. SandyTipper

    SandyTipper Guest

    "SandyTipper" <> wrote in message
    news:0MDgm.38854$Db2.23015@edtnps83...
    >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.
    SandyTipper, Aug 12, 2009
    #2
    1. Advertising

  3. SandyTipper

    Luuk Guest

    SandyTipper schreef:
    > "SandyTipper" <> wrote in message
    > news:0MDgm.38854$Db2.23015@edtnps83...
    >> 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.


    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?


    --
    Luuk
    Luuk, Aug 12, 2009
    #3
  4. On 12 Aug, 19:22, "SandyTipper" <> wrote:
    > 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.
    Captain Paralytic, Aug 12, 2009
    #4
  5. SandyTipper

    SandyTipper Guest

    "Luuk" <> wrote in message
    news:4all.nl...
    > SandyTipper schreef:
    >> "SandyTipper" <> wrote in message
    >> news:0MDgm.38854$Db2.23015@edtnps83...
    >>> 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.

    >
    > 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?
    >
    >
    > --
    > Luuk

    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.
    SandyTipper, Aug 12, 2009
    #5
  6. SandyTipper

    Doug Miller Guest

    In article <lpFgm.38866$Db2.28715@edtnps83>, "SandyTipper" <> wrote:
    >"Luuk" <> wrote in message
    >news:4all.nl...
    >> SandyTipper schreef:
    >>> "SandyTipper" <> wrote in message
    >>> news:0MDgm.38854$Db2.23015@edtnps83...
    >>>> 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.

    >>
    >> 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?
    >>
    >>
    >> --
    >> Luuk

    >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.
    Doug Miller, Aug 12, 2009
    #6
  7. SandyTipper

    SandyTipper Guest

    "Captain Paralytic" <> wrote in message
    news:...
    On 12 Aug, 19:22, "SandyTipper" <> wrote:
    > 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.
    --------------------------
    Doh! Thanks. I was totally confused by the developer tools, but Firefox
    shiowed me the missing right bracket. BTW "It doesn't seem to work"
    meant that nothing showed up, but now I see why. Thanks again.
    SandyTipper, Aug 12, 2009
    #7
  8. In comp.lang.javascript message <0MDgm.38854$Db2.23015@edtnps83>, Wed,
    12 Aug 2009 18:22:52, SandyTipper <> posted:
    >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.

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF3 Op9 Sf3
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr J R Stockton, Aug 13, 2009
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad

    blank cells not showing

    tshad, Jun 13, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    667
    Eliyahu Goldin
    Jun 15, 2005
  2. Replies:
    0
    Views:
    513
  3. UJ
    Replies:
    8
    Views:
    61,125
  4. aualias

    How to access contents of cells within a generated table?

    aualias, Jan 4, 2005, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    207
    aualias
    Jan 5, 2005
  5. Joel Finkel

    Cells[].Text or Cells[].Controls[0]

    Joel Finkel, Sep 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    297
    Joel Finkel
    Sep 1, 2003
Loading...

Share This Page