Newbie: problem found with document.write in function - would love to know why!

W

Warwick Boardman

I found an error due to my incorrect use of the document.write
facility. I'd love to know why it was wrong to use document.write
where I did.

I had a problem using the login script obtainable via
http://www.laughland.biz/javascript.php .

I tried using diagnostic prints using document.write. This didn't
seem to help me so I was pleased to find that there was a new
Javascript debugger available so I downloaded Netscape 7.1 with
Venkman so that I could try to find out what was going on.

I made more than one version of the script and have somehow got one
set of .html/.js files to work as expected. That allowed me to
determine that the use of document.write - as shown commented out in
the script portions below - was a problem.

In Venkman the variable "successpage" was defined up to the point of
the document.write line so that when trying to use it after a
document.write statement it was undefined - hence an error. Yet the
document.write itself did output what was required.

I don't know enough about Javascript to know why it was wrong to use
the document.write command within the function definition code. I'd
love an explanation or a useful specific reference, please.

Relevant parts of the script with the document.write now shown
commented out:

//----------------------------------------------------------------
// Usernames, Passwords & User Pages - These require configuration.
//----------------------------------------------------------------
var successpage = "sysdoc.html"; // The page users go to after login,
if they have no personal page.
var loginpage = "sysdoc_login.html"; //Change this to the page the
login panel is on.
var users = new Array();
..
..
..
//----------------------------------------------------------------
// Login Functions
//----------------------------------------------------------------
function login(username,password){
var member = null;
var loggedin = 0;
 
L

Lasse Reichstein Nielsen

I found an error due to my incorrect use of the document.write
facility. I'd love to know why it was wrong to use document.write
where I did.

Probable cause (without reading your code):
Using document.write after the page has finished loading will erase
the page and start a new one. That erases all variables of the old
page as well/

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top