View Full Version : Writing question

01-17-2009, 06:43 PM
Ok in java if I want to print to prompt I type System.out.print in javascript I write document.write Ok but if I document.write it resets things. I can only do it once... what do i use instead of document.write so it wont reset my program?

thats most likely a really noob question but I can't seem to figure it out how to get around that...

Philip M
01-17-2009, 06:59 PM
The document.write command must be carried out during the loading of the page. So, if it is attached to any event that executes after the page has loaded, then the whole page will be replaced with the contents of the document.write command, as you have found.

The best way is to create a <div> with an id, and then use

var newtext = "Whatever you want";
document.getElementById("yourDivId").innerHTML = newtext;

At least once per year, some group of scientists will become very excited and announce that whatever they announced last year about global warming is wrong.

01-17-2009, 07:39 PM
Ok what did I do wrong?


var date = new Date();
var input = "";
var inputCheck = false;
var menu = "";
var br = "<br />";

var rpsP1 = "";
var rpsAI = "";

var menuComment1 = "1: Rock Papper Scissors" + br + "2: Craps" + br + br + "Type exit to quit";

var rpsComment1 = br + br + "Welcome to Rock Papper Scissors";
var rpsComment2 = br + "Type 1 for Rock, 2 for Scissors and 3 for Paper"

function getInput(input) {

input = ""

do {

inputCheck = false;

try {

input = prompt("Please enter in the info.","");

catch(ex) {

inputCheck = true;
alert("Bad input");



return input;


document.getElementById(mainDiv).innerHTML = menuComment1;

menu = getInput();

if(menu=="1") {

document.getElementById(mainDiv).innerHTML = rpsComment1;

while(true) {

document.getElementById(mainDiv).innerHTML = rpsComment2;

rpsAI = Math.random(Math.floor() *3);
rpsP1 = getInput();