Display javascript value within HTML body

kylex picture kylex · May 26, 2009 · Viewed 33.4k times · Source

i have the following relevant code in the header of my html doc:

test1.value = System.Gadget.Settings.read("Date1");

And I'm trying to display the test1 value in the body of my html doc.

It displays when i use:

<input type="text" id="test1" />

But isn't working when i use (in the body):

<script type="text/javascript">
    document.write(document.getElementById('test1').id);
</script>

Any suggestions would be greatly appreciated

Answer

Jeff Meatball Yang picture Jeff Meatball Yang · May 26, 2009

This might be obvious, but why not just write:

<html>
  <body>
    <div>Here's the Date1 value: 
      <script type="text/javascript">
        document.write(System.Gadget.Settings.read("Date1"));
      </script>
    </div>
  </body>
</html>

If this does not do what you want, please explain what your expected output is.