View Full Version : Username/Password validation using Select Case

06-19-2004, 04:50 AM

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

<title>Login Form</title>

<!--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">

<!--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>
<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 -->
<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>

<!--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">

<script language="javascript">

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

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

<!-- Assign intPrice to txtPrice textbox -->

<!-- Assign intTax to txtTax textbox -->

<!-- Assign intTax to txtTax textbox -->

switch (strUserName){

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




Willy Duitt
06-19-2004, 05:32 AM
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.

06-19-2004, 02:19 PM
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!


Willy Duitt
06-19-2004, 02:44 PM
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. :thumbsup:
And welcome to Coding Forums.... ;)