No document.write() : ti cancella tutta la pagina.

Devi usare
getElementById('ID_OGGETTO').innerHTML = "nuovo testo";