Results 1 to 8 of 8

Thread: I am just playing around...but

  1. #1
    Join Date
    Feb 2006
    Location
    Lakeville, MN
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I am just playing around...but

    Ok, I am no programmer and am just playing around. Kind of a hobby.
    Anyway, I have this script and I am wondering why the <td align=center/> has no effect on the item placed in the cell? The first <td align=center> in pure HTML works fine but not inside the script (seen lower in red). The 'count' still aligns to the left.

    Thanks


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    </head>
    <body>

    <div align="center">
    <table border=1>
    <tr>
    <td width=200 align=center>
    hi
    </td>
    </tr>
    </table>
    <table>
    <tr>
    <td>
    <input type="button" value="push me" onclick="a()">
    </td>
    </tr>
    </table>

    <script>
    function a(){
    var count = 0;
    while (count<11)
    {
    document.write("<table align=center width=50% border=1/><tr/> <td align=center/>"+count+"</td></tr/></table/><br/>");
    count++;
    }
    document.write("Loop done!");
    }
    </script>

    </td></tr></table>
    </body>
    </html>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Firstly, attribute values must be quoted (so that's align="center" or even align=\"center\" being as you're using Javascript) unless they're pure number values (no units or funny business), and even then it doesn't hurt. Secondly, it's a recommendation that you leave a space before the / of a self-closing tag to seperate it from the last attribute.
    Try:
    Code:
    document.write("<table align=\"center\" width=\"50%\" border=1 /><tr><td align=\"center\" />"+count+"</td></tr></table><br />");
    Nothing to do with your problem, but I should point out that every single attribute you've applied to that table and td has been superseded by CSS.
    Code:
    HTML            CSS
    width="50%"     width: 50%;
    align="center"  text-align: center;
    border=1        border: solid 1px;
    Last edited by Twey; 02-24-2006 at 05:48 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2006
    Location
    Lakeville, MN
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks that worked great!
    As to the CSS, yes I know (sort of) I use CSS on my web site.
    I am just now trying to learn some JavaScript and am working out of the book "The Complete Reference JavaScript 2nd ed". More for fun than anything. And I am taking some of their examples and making them do more in an attempt to really understand what is going on.

    Thanks again!
    P.S. I am sure I will be back with more questions as I go through the book. I hope my questions are not too simple and help others also.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I am taking some of their examples and making them do more in an attempt to really understand what is going on.
    Best way to learn a language, short of launching into a project.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Too late, I know but, why would you ever need to self close a td tag?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Woah... I should have noticed that. Probably about the same time I saw </tr/>. Bartfast: I think you missed the point of self-closing tags. They're used for tags that don't have an ending tag.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    Too late, I know but, why would you ever need to self close a td tag?
    If we were considering XML, or an application of it, then it's quite legitimate to replace any occurances of:

    Code:
    <tag></tag>
    with:

    Code:
    <tag/>
    no matter what tag may be.

    However, we are not considering XML. The OP is using HTML and empty-element (a.k.a. self-closing or minimized start-) tags do not exist. A forward slash should only occur in tags within a (quoted) attribute value or as part of the end tag[1].

    Mike


    [1] If HTML was parsed as an application of SGML this statement wouldn't be applicable, though it would be a good idea as NET are obscure.

  8. #8
    Join Date
    Feb 2006
    Location
    Lakeville, MN
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    Woah... I should have noticed that. Probably about the same time I saw </tr/>. Bartfast: I think you missed the point of self-closing tags. They're used for tags that don't have an ending tag.
    Well, I think I get it now. Thanks. This book has not address 'self-closing tags' as of yet. I was just jumping in with one of their examples that had one in it without explicitly explaining what ‘it’ was, but it worked for their example. But now I see just what they are used for with your explanation.
    Sorry for being such a neophyte with all of this but when you are taking the 'self taught' approach that is what you get. You know, I know just enough to be dangerous!
    More dangerous questions to come so watch out!

    Thanks to all of you for your help and patience!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •