manipulating table cell's data with js...

javascript Canada
  • 18 years ago

    is it possible?


    ex. want to insert a date into a table cell...easy with asp/php etc. but want to do this with js...how do i refer to that table cell to show the current date/time?


    TIA

  • 18 years ago

    Give the cell a name, like this:

    Code:
    <table>
    <tr><td id="clock"></td></tr>
    </table>

    Then insert the current date and time into the cell with the following line of code (only works in IE):
    Code:
    document.all["clock"].innerText=(new Date());

    If you need to it continually update, simply set an interval for it with the window.setInterval() method.


    Incidentally, this will work with almost any object in a web page that can contain HTML, like a DIV or a SPAN.


    If you need it to work in Netscrape 4.x, I'd use an INPUT box instead and set it like this:

    Code:
    document.formName.elementName.value=(new Date());

    Hope that helps.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer Science is no more about computers than astronomy is about telescopes.” - E. W. Dijkstra