document.write ALWAYS launches a new page, unless it loads. After the current page finishes loading, all document.write documents will be written to the NEXT web page, which will be displayed, not the current one, because it has already been written.
use DOM methods like this:
<script type="text/javascript"> function result() { var a, b, c; a = 10; b = 20; c = a+b; document.getElementById('foo').innerHTML = "The result of a+b is" + c; return false } </script> <span id="foo"></span> <input type="button" value="Result" onclick="return result();">
source share