SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Output a string to an XHTML div?

    I have a javascript clock for my history website. It's supposed to remind everyone that history is now... or whatever

    Right now I'm writing the clock variable, strClock, to a text box.

    Code:
        document.ClockForm.ClockBox.value=strClock; 
        dateDate=setTimeout("ecClock()",1000);
    The text box is causing validation problems, and anyone without javascript just sees an empty text box sitting there. I'd prefer to replace it with a CSS styled div.

    Can I do this? And what's the syntax? I'm guessing it has something to do with innerHtml, but I've never gotten a working script to write/remove/replace anything on a webpage that way. I'm hoping there are some trick in that direction that apply to this situation. I want something more standards compliant and more accessible.
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  2. #2
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this maybe...

    Code:
    <script language="JavaScript">
    document.getElementById('DivExample').innerHTML="Good Afternoon";
    </script>
    Code:
    <div id="DivExample">
    Hello World
    </div>

  3. #3
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, after all the trouble I've had looking up this info, it doesn't seem fair that it should be this simple, but I'll let you know if this works.
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  4. #4
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I owe you big time! You just wiped out 5 separate validation errors and one major accessability issue for my webpages.

    Thanks!
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    That will work fine for an HTML div but if you want it to work with XHTML instead of HTML then you will have to substitute the appropriate DOM commands with the appropriate namespace references.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is an HTML 4 technique?? Well, !#$^@#@#$%!$%$@!

    *deep breath* I guess it's back to puzzling out DOM commands from the random bits of unobtrusive code I can google. *sigh*

    Thanks for the heads up. It works fine now, but this is exactly the kind of thing that will break as soon as servers actually switch over to XHTML, right?
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    XHTML does not support document.write or innerHTML or even document.createElement - you have to use document.createElementNS in order to specify which namespace you are creating the element in for XHTML. The code will then NOT work when the page is served as HTML.

    JavaScript for DOM access in HTML is completely incompatible with JavaScript for DOM access in XHTML because of namespace considerations. If you are going with XHTML then you need to always serve the page that way in order for the JavaScript DOM calls to work unless you use server side processing to completely replace all the DOM calls within the JavaScript when serving as HTML.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Stephen, you're awesome.

    You guys have an answer for everything.
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  9. #9
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    Fortunately for me!
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.


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
  •