Hi Everyone.

I am fairly new to javascript and wanted to do a small site that basically has a form where you select your name from a drop down menu, insert your password in the password box and press log in, the page then quickly checks if the inputed password matches the one stored and if it does it automatically redirects to another page (which in this case is the user's personal page)

What i have written at the moment is :

<script type="text/javascript">

function verify(menu,pass){
	
	var setpass = "a";

	var lowpass = pass.toLowerCase();

	if(menu == "Alex" && lowpass == setpass){
		alert("APROVED");
		window.location = "Alex_main.html"; 
	}

	else{
		alert("ERROR");
	}
}
</script>

It Shows the alerts but it does not redirect to the page, i am unsure why...

Here is the form i am using:

<form name="LogIn1" method="post">

		<table>
			<tr>
				<td><select name="URLselect">
	
 				<option selected value="Alex">Alex
	
     				</select></td>
			</tr>
			<tr>
				<td><input type="password" name="pwdPassword" size="12" /></td>
			</tr>
			<tr>
				<td><input type="button" onClick="verify(document.LogIn1.URLselect.value,document.LogIn1.pwdPassword.value)" value="Log in" /></td>
			</tr>
		</table>
	</form>

What i basically want it to do is check if the password matches with the one that has been previously declared and if it does to redirect the user to his page.

(this is for more or less personal use , in other words i dont see it ending up beeing hosted on the internet. I want to use it as a desktop background site for quick access.)

Also if its not too much trouble, i wanted to ask, is there a way that i can somehow record the logins?
So that for example i can come and see that John has logged in 5 times and Alex has logged in 2 times.

That would be very helpfull!

Thanks in Advance
-- Roiie

try using window.location.href

Also if its not too much trouble, i wanted to ask, is there a way that i can somehow record the logins?
So that for example i can come and see that John has logged in 5 times and Alex has logged in 2 times.

That would be very helpfull!

you can always write to a text file
ie:

function wtf(){
var fso, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
s = fso.CreateFolder("C:\\test.txt", true);
s.writeline("This is a test");
s.Close();
}

you can always write to a text file
ie:

function wtf(){
var fso, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
s = fso.CreateFolder("C:\\test.txt", true);
s.writeline("This is a test");
s.Close();
}

Hmm i tried this and it does not seem to do anything, i am not sure if its because i changed the

s = fso.CreateFolder("C:\\test.txt", true);

to

s = fso.CreateFolder("C:\Documents and Settings\Default\Desktop\test.txt", true);

but it does not do anything ...

I would apreciate it if you could help me with this logging of logins, as it would make it easier to keep track of users. Also, is there any way that it doesent ask you for activeX control, because it would mean that if someone presses no on the alert it would not do what its supposed to do, does it not?

Thanks in Advance
--Roiie

Thats not exactly how you do it, look up javascript file io online

s = fso.CreateFolder("C:\Documents and Settings\Default\Desktop\test.txt", true); has incorrect escaping. You need to escape the \ character. Do something like s = fso.CreateFolder("C:\\Documents and Settings\\Default\\Desktop\\test.txt", true); though this is not a recommended approach.

Replace window.location = "Alex_main.html"; with window.location.replace("Alex_main.html"); assuming that the file resides on the same path as that of the current file.

As far as persisting the state is concerned, use cookies if you are doing this client side, though it beats me why you would do password validation on client side.

s = fso.CreateFolder("C:\Documents and Settings\Default\Desktop\test.txt", true); has incorrect escaping. You need to escape the \ character. Do something like s = fso.CreateFolder("C:\\Documents and Settings\\Default\\Desktop\\test.txt", true); though this is not a recommended approach.

What do you mean by its not a recommended approach?

As far as persisting the state is concerned, use cookies if you are doing this client side, though it beats me why you would do password validation on client side.

Well I am doing this client side because as i said before its for use on my personal computer, its not really going to end up hosted or anything like that. If it was i would have gone with php instead.

The problem is that anyone can display your code and find out the passwords.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.