There is nothing you can just add to the code snippet you've got. Once it has s written it's stuff to the document, it's done it's job and that's it. Game over.
So here is some sample code to look at for each of the 4 steps (I'm just typing it straight in without testing so apolgies if I give you errors).
2 & 3 (put in the head):
Of course the document.all part won't work in Netscape, so doe a search for browser sniffing scripts and "getElementById" for info about accessing an element's properties in Netscape.