Click to See Complete Forum and Search --> : help!! open book test- why can't i view source code on this page


1christine
12-22-2003, 07:39 PM
<HTML>
<HEAD>
<TITLE>Questionnaire</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function questionnaire(){
var info = new Array();
info[0] = prompt("Please enter your name.","Name");
info[1] = prompt("Please enter your street address.","Address");
info[2] = prompt("Please enter your city, state, and zip code.","City, State, ZIP");
info[3] = prompt("Please enter your telephone number.","Telephone");
document.write("<H2>Your personal information is:</H2>");
for(var i=0; i<4; ++i){
document.write(info[i] + "<BR>");
}
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>
</HEAD>
<BODY onLoad="questionnaire();">
</BODY>
</HTML>

gil davis
12-22-2003, 07:48 PM
Because the document is never complete. You cannot veiw source until the document is complete. You need a document.close() statement.

1christine
12-22-2003, 07:51 PM
didn't work

AdamGundry
12-23-2003, 04:18 AM
The problem is that you are calling document.write() after the document has closed, and the onLoad event handler fired. This will call an implicit document.open(), and hence clear the source code. If you want the source to be preserved try this:

<HTML>
<HEAD>
<TITLE>Questionnaire</TITLE>
</HEAD>
<BODY>
<SCRIPT type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
var info = new Array();
info[0] = prompt("Please enter your name.","Name");
info[1] = prompt("Please enter your street address.","Address");
info[2] = prompt("Please enter your city, state, and zip code.","City, State, ZIP");
info[3] = prompt("Please enter your telephone number.","Telephone");
document.write("<H2>Your personal information is:</H2>");
for(var i=0; i<4; ++i){
document.write(info[i] + "<BR>");
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>
</BODY>
</HTML>
Adam

fredmv
12-23-2003, 04:21 AM
You could also consider using the code I originally provided (http://forums.webdeveloper.com/showthread.php?s=&threadid=24005#post124511). ;)

1christine
12-23-2003, 06:25 AM
Thanks guys.
I used some code that fredmv had suggested before.