/    Sign up×
Community /Pin to ProfileBookmark

help!! open book test- why can’t i view source code on this page

<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>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisDec 23.2003 — Because the document is never complete. You cannot veiw source until the document is complete. You need a document.close() statement.
Copy linkTweet thisAlerts:
@1christineauthorDec 23.2003 — didn't work
Copy linkTweet thisAlerts:
@AdamGundryDec 23.2003 — 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:

&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Questionnaire&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;SCRIPT type="text/javascript"&gt;
&lt;!-- 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("&lt;H2&gt;Your personal information is:&lt;/H2&gt;");
for(var i=0; i&lt;4; ++i){
document.write(info[i] + "&lt;BR&gt;");
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS --&gt;
&lt;/SCRIPT&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;

Adam
Copy linkTweet thisAlerts:
@fredmvDec 23.2003 — You could also consider using [url=http://forums.webdeveloper.com/showthread.php?s=&threadid=24005#post124511]the code I originally provided[/url]. ?
Copy linkTweet thisAlerts:
@1christineauthorDec 23.2003 — Thanks guys.

I used some code that fredmv had suggested before.
×

Success!

Help @1christine spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...