PDA

View Full Version : error at line 1, char 1 ??


BDT
04-25-2003, 04:20 PM
I want to use JS for a page with several images each with several small text links superimposed on it. Both the images and the text in the links will change dynamically with screen interactions. I think that I need to 'paint' the screem with a function so that I can rerun the function when the various text and images change.

Anyway, I tried without success to get this to work, but keep getting an error at line 1 / character 1.

Here is a simple script that shows the problem. I suspect that I'm missing something obvious and hope that someone can explain why this approach isn't working.

thanks, BDT

<html>
<head>
<title>Hex Game</title>
<script language="javascript" type="text/javascript">
var h = 23;
function drawscreen() {
document.write(h + "<hr>");
document.write('<form1><input type="button" value="click" onClick="update()"></form1>');
}
function update() {
h=h+1;
// alert("h= " + h);
drawscreen();
}
</script>
</head>
<body onLoad="drawscreen();">
</body>
</html>

cheesebagpipe
04-25-2003, 04:28 PM
Read "Warnings:" here -

http://www.dardenhome.com/js/x280336.htm

...then re-think your approach. :confused:

liorean
04-25-2003, 05:25 PM
document.write only works while the document is still loading and you are calling it first when the document has finished loading.

BDT
04-25-2003, 11:45 PM
OK, that makes sense. I tried to use document.write in the body with some variables that changed with various events. One of the things that changed was the content of text and text links. However when these variables changed, the screen didn't. So I thought that if I used the same script

Am I missing something. I have used variables to change image sources that I initially specified in document.write statements and these updated the screen as soon as the event happened. Any idea why text wouldn't change and what I need to do to achieve this? I can change the text to images, but I can't imagine that is the only way to procede.

I appreciate anyone's thoughts on this.

cheers, BDT

cheesebagpipe
04-25-2003, 11:59 PM
I'd start here (http://www.brainjar.com/dhtml/intro/).

document.write() - called on a closed document - does strange things, particularly in MSIE. It may sometimes seem to be working, but, don't hold your breath (and don't, period). DOM-based document manipulation is now pretty well supported, with some irregularities, so start reading. ;)

An image's .src property is just an object property, read/write - changing it at any time causes the browser to reload the new image in the document, without disturbing anything (images are 'replaced' elements, in a world of their own). Very different from calling document.write(), the monster-truck of page modification.