views:

56

answers:

2

I'm trying to create an updating clock in Javascript. Everything is working correctly as I step through the debugger, except that it's not actually updating the span. Any ideas why?

<script type="text/javascript">
// The following line of code is in a setInterval() 
// time is set correctly, according to my debugger
 document.getElementById('clock').value = time;
}
</script>
<span id="clock">This should update
</span>
+6  A: 

Change value to innerHTML

document.getElementById('clock').innerHTML = time;

value is only a valid attribute for form elements like input or option.

Doug Neiner
A: 

Hey,

Also, to have it refresh (if you are doing a clock), use window.setTimeout;

window.setTimeout(function() { document.getElementById('clock').innerHTML = 'XYZ'; }, 500);

500 is millisecond value.

Brian
Brian, your answer still includes his error. He also states he is already using `setInterval` though the partial pasting of the code is confusing.
Doug Neiner
My statement was an add on to the existing answer, hence the ALSO part of my comment. He said setInterval, I did setTimeout in mine.
Brian
@Brian `getElementById('clock').value` is invalid code. You can't post broken code and expect it to help the OP out.
Doug Neiner
Oh, I guess I did. It's fixed above. Long week...
Brian