Forum Moderators: open
The login page -
<HTML>
<HEAD>
<TITLE>Member Info</TITLE>
</HEAD><BODY BGCOLOR="black" TEXT="white">
<CENTER><H2>Player Login</H2></CENTER>
<CENTER>
<TABLE BORDER=1 CELLPADDING=10>
<TR><TD>
<FORM METHOD="Login" ACTION="verify.html">
</CENTER>User:     <CENTER><INPUT TYPE="text" NAME="ID" WIDTH=10><BR>
</CENTER>Pass:     <CENTER><INPUT TYPE="password" NAME="PW" WIDTH=10>
<BR>
<CENTER>
<INPUT TYPE="submit" VALUE="Login" onClick="function Login()"> <INPUT TYPE="reset" VALUE="Reset">
</CENTER>
</TD></TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
The actual performing script page -
<HTML>
<HEAD>
<SCRIPT LANGUAGE="javascript">
<!-- PASSWORD PROTECTION PROGRAM -->
<!-- Begin
function Login()
{
var done=0;var ID=ID;
ID=ID.toLowerCase();
var PW=PW;
PW=PW.toLowerCase();
if (ID=="xxx" && PW=="xxx") { window.location="thankyou.html"; done=1; }
if (done==0) { alert("You have typed in an invalid Character Name and/or Password. Please try again."); }
}
// End -->
</SCRIPT>
</HEAD>
<BODY onLoad="Login()">
It will load the script page but cannot find the ID and PW variables loaded from the previous page; however, in the Address line it shows this:
file:///blah blah/verify.html?ID=xxx&PW=xx
but still cannot find variables.
Help!
...cannot find the ID and PW variables loaded from the previous page;
however, in the Address line it shows this:
file:///blah blah/verify.html?ID=xxx&PW=xx
JavaScript variables only exist on a per page basis as objects you can address. So you need to perform some "surgery" to extract the variables from the URL's query string, using JavaScript's substring() method.
The substring() method takes two arguments: the start position and the end position of the substring being extracted. Not to be confused with the substr() method -- that takes a start position argument, and the length of the requested substring from there on.
fullURL = document.URL
qString = fullURL.substring(fullURL.indexOf('?')+1, fullURL.length)
That much gives you a variable named qString which contains everything after the question mark. Then you'll need to chop qString up into its two parts so you can declare your ID and PW as objects for THIS page.
I'll leave that part as a homework exercise ;)
[edited by: tedster at 10:23 pm (utc) on June 15, 2003]