...

View Full Version : I need help with this piece of JavaScript...



atrsite
12-08-2004, 04:36 AM
<script type="text/javascript">
function validate()
{
var entry = document.forms.f.pwd1.value.toLowerCase();
if( entry == "mike") window.location = "contentpage.htm";
else
{
alert("Password is Incorrect, you should not be here");
document.forms.f.pwd1.value="";
}
}
</script>

What is wrong with this... I am putting it on my webpage, but it isn't working, and I have looked over it a billion times... maybe it is something to do with the validate function, and the browser not understanding it? Hmm...Help plz!

Brandoe85
12-08-2004, 04:58 AM
Can you post your form? Is your form name 'forms' if not im assuming you wanted to put forms[0]?

glenngv
12-08-2004, 05:18 AM
http://www.codingforums.com/showthread.php?t=10114

atrsite
12-08-2004, 05:19 AM
No... I don't have any form syntax...(except for in the var and if statements.)
I am trying to get a password validation field.
P.S. Thanks Glenn for your script, although I plan to use it for reference, since I am trying to learn on my own.

atrsite
12-08-2004, 05:42 AM
Now that I think of it, I should have a form to apply the validation to, but how would I implement that? All I want is a username and password box to show up, then when they enter the right combo it should go to the page.

glenngv
12-08-2004, 05:46 AM
<script type="text/javascript">
function validate(oForm)
{
var pwd = oForm.pwd1.value.toLowerCase();
if (oForm.username.value.toLowerCase() == "atrsite" && oForm.pwd1.value.toLowerCase() == "mike"){
window.location = "contentpage.htm";
}
else
{
alert("Username or Password is incorrect, you should not be here.");
oForm.username.focus();
}
}
</script>
...
<form name="f">
<input type="text" name="username" />
<input type="password" name="pwd1" />
<input type="button" value="Login" onclick="validate(this.form)" />
</form>

atrsite
12-08-2004, 06:17 AM
<table>
<tr>
<td>Username: </td><td><input type="text" name="user" /></td>
</tr>
<tr>
<td>Password: </td><td><input type="text" name="pass" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Login" /></td>
</tr>
</table>
</form>

Form action:
<script type="text/javascript">
function validate()
{
var entry = document.forms[1].form1.pwd1.value.toLowerCase();
if( entry == "mike") window.location = "contentpage.htm";
else
{
alert("Password is Incorrect, you should not be here");
document.forms[1].form1.pwd1.value="Try Again";
}
}
</script>

atrsite
12-08-2004, 06:19 AM
thanks...!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum