Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-19-2004, 03:50 AM   PM User | #1
Kevinito
New to the CF scene

 
Join Date: Jun 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Kevinito is an unknown quantity at this point
Username/Password validation using Select Case

Hi!

I am busting my head attempting to figure out this code. As you can see, if you type the username "KFoster" and the password "MST3K", you should be directed to another website. I've been through the code several times but to no avail. Here it is . . . (sorry it is heavily commented)

-Many thanks

<html>
<head>
<title>Login Form</title>
</head>

<!--Begin body of HTML document with formatting -->
<body background="../bkgnd.gif">

<H1 align="center"><font color="#000080" face="Verdana">Hidden Valley Vineyards Login Form</H1>
<center><img src="vine.jpg"></center>

<!--Form Name is frmLogin -->
<form method="post" name="frmLogin" action="javascript:void(0)">

<center><table border="0" width="300" cellspacing ="0" cellpadding="1">
<tr>

<!--Create 2 text boxes and assign values -->
<td><font color="#000080" face="Verdana">User Name: </td><td><input type="text" name="txtUserName" size="22"></td><br><br>
</tr>
<tr>
<td><font color="#000080" face="Verdana">Password: </td><td><input type="text" name="txtPassword" size="22"></td> <br><br>

<!-- Create Dropdown list for all departments -->
<tr>
<td><font color="#000080" face="Verdana">Department: </td>
<td><select size="1" name="1stDepartment">
<option value="../administration">Administration</option>
<option value="customer">Customer</option>
<option value="employee">Employee</option>
<option value="finance">Finance</option>
<option value="hr">Human Resources</option>
<option value="it">Information Technology</option>
<option value="management">Management</option>
<option value="manufacturing">Manufacturing</option>
<option value="marketing">Marketing</option>
<option value="webmaster">Webmaster</option>
</select>
</td>
</tr>
</table>

<br><br>
<!--Create 1 button and assign a function(login()) to the button(btnLogin) -->
<input type="button" value="Go to the Department Website" name="btnLogin" onClick="login()">

<!--Create 1 button to clear the screen -->
<input type="reset" value="Clear Form" name="btnClear">
</form>
</center>
</body>

<script language="javascript">

<!-- Create function login() -->
function login(){

<!-- Declare three variables -->
var strUserName, strPassword, strDepartment;

<!-- Assign intPrice to txtPrice textbox -->
strUserName=document.frmLogin.txtUserName.value;

<!-- Assign intTax to txtTax textbox -->
strPassword=document.frmLogin.txtPassword.value;

<!-- Assign intTax to txtTax textbox -->
strDepartment=document.frmLogin.1stDepartment.value;

switch (strUserName){

case "KFoster":
if (strPassword == "MST3K") {
window.location.href = strDepartment + ".htm";
}
else{
window.location.href = "loginFormJS.htm";
}


break;

}
}
</script>

</html>
Kevinito is offline   Reply With Quote
Old 06-19-2004, 04:32 AM   PM User | #2
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
The biggest problem is that names can not begin with a numeric.
Rename your select option menu.
  • <select size="1" name="1stDepartment">

A few other problems are:

Move your script into the <head> of the document.
Currently it appears after the closing body tag.

Using this script/approach. Your login is not secure in that a user can simply view source and grab a username/password or the next page value.
Willy Duitt is offline   Reply With Quote
Old 06-19-2004, 01:19 PM   PM User | #3
Kevinito
New to the CF scene

 
Join Date: Jun 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Kevinito is an unknown quantity at this point
It Works!

That's it! The code now works. It's no big deal the source can be seen, it was just a test to see if I could do it. Many thanks!

If you have Paypal, just give me your account and I'll send you five bucks for your help!

Many thanks!

Kevin
Kevinito is offline   Reply With Quote
Old 06-19-2004, 01:44 PM   PM User | #4
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
I'm happy to hear you were able to resolve your problem.
But, although I appreciate your offer of remuneration there really is no need. You will find that the members of Coding Forums volunteer their time and freely assist anyone seeking a solution to any number of coding problems.

Glad I could help.
And welcome to Coding Forums....

.....Willy
Willy Duitt is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:59 AM.


Advertisement
Log in to turn off these ads.