SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript in HTML Tables

    http://www.webreference.com/js/column2/format.html

    I read on the above tutorial that one should NEVER place a script in an HTML table, especially if it has doument. write in it. Does anyone know why this would be true? I have a date and time script in my HTML table and have no problem with it. Your thoughts???

    Block

  2. #2
    SitePoint Evangelist azizur_rahman's Avatar
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume you are reffering to the last para:

    If you would like to display the date somewhere in an HTML table, you're in trouble. Never embed a script in a table, especially if it has a document.write() statement. At this time there is no workaround for this annoying bug (besides printing the entire table in JavaScript, or using Dynamic HTML).
    I am not total sure of what they meant there.. but I put document.write in HTML table and nothings happends... I also use the VB version and still nothing happens... chnaces of somene's browser having problme (seems to me) is next to nothing.

    When ever I want to put the current date and time I just simply use the document.wite and it works fine.. I dont know what that person is meant...


    I am assuming they are referring to the JS code just above the para, I can see there is problem.. but what if that was put inside a function so we just make a call to the function and it prints out the date as it called.

    I think the author has some reason for saying that, which should have been made clear but I dont agree with her/him.
    Azizur Rahman
    Web Application Developer

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the only thing that document.write would do is if you have it in a onclick event which would clear the screen, but as for that comment, it sounds kind of stupid unless, you put the script in the wrong place like outside a tr or td tag etc, which would simply treat it as a comment tag and print it at the top of the table or something like that.

    And in anycase I would use
    innerHTML/outerHTML/innerText/outerText
    to modify the content if using an event to write to the document, unless you want a clean page of course

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    northern Maine
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this had to do with an old NS3(?) bug with document.write()-ing inside a <td>...
    Jason - Contact Me
    Supermoderator @ CodingForums

  5. #5
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I never use document.write - i think it's bad practice unless
    you're creating a new window with only one line - and
    even then i'd probably just create an object and use, as Andrew quite rightly said, innerHTML/innerText


    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  6. #6
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To be honest i aint one for cross browsability with netscape, but i thought innerHTML was a ie only feature. Then again i think flawless is like me with cross browsability.

  7. #7
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope - innerHTML is universal - I believe.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  8. #8
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Flawless_koder
    Nope - innerHTML is universal - I believe.

    Flawless
    Alas not - it's not part of the W3C standards... NS6 only implemented it because loads of developers wanted it. Thus NS4.x does not support it. Dunno about Opera...

    Read up here:
    http://www.webreference.com/js/tips/001209.html
    http://www.mozilla.org/docs/web-deve...e_2.html#other

    However, this is a good guide to the cross-browser alternative:
    http://www.pxl8.com/cloneNode.html

    Don't give me wrong, I'm leaning towards ignoring NS4 users (!) but because others read and act on these posts I thought it was important to set the record straight!
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  9. #9
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    arr k cheers m@rco, why can't people just upgrade or all developers force people to upgrade as some people dont even know what an upgrade is or how to do it lol, from what i saw the other day

  10. #10
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Exactly! It's not just to make life easier for us - they benefit from a richer experience at the end of the day.

    See another post in this forum for the whole W3C standards conformance shebang! (which I'm 100% behind incidentally, but I'm ultimately forced to target IE in the meantime....)
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  11. #11
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well as long as standards keep moving the way they are we should have no problem with the damn hassle of cross browsability, what with xhtml(strict) and xml should help people view correctly and not have any hassles with the engines that microsoft or netscape use.

  12. #12
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OUCH @ trying to do anything constructive without
    innerHTML. I use it often instead of passing
    variables around

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


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
  •