Nobby
04-11-2006, 02:53 AM
I have a password page where clients can enter a predetermined password. I have it set up so that the ID and Password are stored on a page called pwd.js and when the client enters his password a function, pasuser(form), is called from pwd.js. I'm new to javascript and what I can't work out is how to use this for more than one password. Can I use "else if" and enter different passwords and if so where do I put the code? Can anybody help please?
Here is the code I have:
password code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script language="javascript" type="text/javascript" src="pwd.js"></script>
</head>
<body>
<table width="780" border="0" cellspacing="2" cellpadding="2" >
<form name="login">
<tr>
<td><font color=#999999 size="2" face="arial">User Name:</font></td>
<td><input name="id" type="text" value size="36"></td>
</tr>
<tr>
<td><font color=#999999 size="2" face="arial">Password:</font></td>
<td><input name="pass" type="password" value size="36"></td>
</tr>
<tr>
<td><input type="button" value="Login" onClick="pasuser(this.form)">
<input type="Reset">
</td>
</tr>
</form>
</table>
</body>
</html>
pwd.js code
<!--//
function pasuser(form) {
if (form.id.value=="client1") {
if (form.pass.value=="password") {
location="client1/page1.html"
} else {
alert("Invalid Password")
}
} else { alert("Invalid UserID")
}
}
//-->
Any help would be greatly appreciated
Here is the code I have:
password code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script language="javascript" type="text/javascript" src="pwd.js"></script>
</head>
<body>
<table width="780" border="0" cellspacing="2" cellpadding="2" >
<form name="login">
<tr>
<td><font color=#999999 size="2" face="arial">User Name:</font></td>
<td><input name="id" type="text" value size="36"></td>
</tr>
<tr>
<td><font color=#999999 size="2" face="arial">Password:</font></td>
<td><input name="pass" type="password" value size="36"></td>
</tr>
<tr>
<td><input type="button" value="Login" onClick="pasuser(this.form)">
<input type="Reset">
</td>
</tr>
</form>
</table>
</body>
</html>
pwd.js code
<!--//
function pasuser(form) {
if (form.id.value=="client1") {
if (form.pass.value=="password") {
location="client1/page1.html"
} else {
alert("Invalid Password")
}
} else { alert("Invalid UserID")
}
}
//-->
Any help would be greatly appreciated