views:

1319

answers:

2

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

+4  A: 

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.

Jeff Meatball Yang
A: 

That doesn't work because your script is in the header of your page and the declaration os the input text1 is in the body .. so what happends is that when the browser runs the script it won't find the object.

You will need something like this ...

<html>
  <body>
    <input type="text" id="test1" />
    <script type="text/javascript">
      document.write(document.getElementById('test1').id);
    </script>
  </body>
</html>
João Guilherme
funny, we basically came up with the same HTML.
Jeff Meatball Yang