Set value of field from JavaScript

Can anyone help me? How can I set the values in Javascript to a field? I used JS Header. Is there any other way?

e.g. I have a field named “txtTime”

I use the following code in notes to display a clock:

and I use the following code in JS Header:

var f = document.forms[0];

var theTime;

theTime = f.txtTime.value;

f.txtTime.value = theTime;

There’s an error when I run it in IE:

‘f.txtTime’ is null or not an object.

How to fix it?

Thanks.