I am having a problem with my homework I cant seem to get the redirection with onClick. The script is supposed to have the user insert the name and password and the choose a department from a drop down. The instruction state that we have to use a case statement. Below is the code. I’m new here to this forum so please forgive my messiness in the post. Any help will be greatly appreciated THANKS in advance! I know its choppy and I have changes things up so many times I'm sure my mistakes are in the if statement throught the case ......
here is the script: - <form method = "post" name= "frmlogin" action = "javascript:void(0)">
-
-
User Name<br />
-
<input type ="text" name ="txtUserName"><br />
-
<br />
-
Password<br />
-
<input type ="text" name ="txtPassword"><br />
-
<br />
-
Department</b>
-
<select name = "1stDepartment">
-
<option value="employee.htm">Employee</option>
-
<option value="customer.htm">Customer</option>
-
<option value="administration.htm">Administration</option>
-
<option value="finance.htm">Finance</option>
-
<option value="hr.htm">HR</option>
-
<option value="it.htm">IT</option>
-
<option value="managment.htm">Managment</option>
-
<option value="manufacturing.htm">Manufacturing</option>
-
<option value="marketing.htm">Marketing</option>
-
<option value="webmaster.htm">Webmaster</option>
-
</select><br />
-
<br />
-
<input type="button" name= "btnLogin" value="Go to the Department Web Site" onClick ="login()" >
-
-
<input type="reset" name= "btnClear" value="Clear Form">
-
-
-
</form>
-
-
<script language = "JavaScript">
-
function login(strUserName){
-
var strUserName, strPassword, strDepartment;
-
strUserName = document.frmlogin.txtUserName.value;
-
strPassword = document.frmlogin.txtPassword.value;
-
strDepartment = document.frmlogin.value;
-
-
switch (strUserName){
-
case "kFoster":
-
if (strPassword = "MST3K"){
-
window.location.href= ("strDepartment.htm");
-
}
-
else{
-
location.href= ("loginFormJS.htm");
-
}
-
break;
-
case "CSchawab":
-
if (strPassword = "OKC802"){
-
location.href= ("strDepartment.htm");
-
}
-
else{
-
location.href= ("loginFormJS.htm");
-
}
-
break;
-
case "FHelms":
-
if (strPassword = "telcom52"){
-
location.href= ("strDepartment.htm");
-
}
-
else{
-
location.href= ("loginFormJS.htm");
-
}
-
break;
-
case "kShea":
-
if (strPassword = "Ghost716"){
-
location.href= ("strDepartment.htm");
-
}
-
else{
-
location.href= ("loginFormJS.htm");
-
}
-
break;
-
}
-
-
-
}
-
</script>
5 1481
Hi mcc welcome to TSDN,
inside your if statements you are using a single equal sign "=", that means your assigning values and it is always true. what you want to do is change
those in the if statement to double equal signs "==", that will test the considtions and return true or false and based on your code it do perform a certain task.
Hi mcc welcome to TSDN,
inside your if statements you are using a single equal sign "=", that means your assigning values and it is always true. what you want to do is change
those in the if statement to double equal signs "==", that will test the considtions and return true or false and based on your code it do perform a certain task.
Thanks I should have known better! Let me give that a try
Thanks again!
Thanks for the welcome...forgot to add that. Anyways I used the == instead of the =. Changed things up.I dont get any errors in IE or FireFox error council, but is still does not direct to the page or any error page. Still stuck!
Thanks
redone - <form method = "post" name= "frmlogin" action = "javascript:void(0)">
-
-
User Name<br />
-
<input type ="text" name ="txtUserName"><br />
-
<br />
-
Password<br />
-
<input type ="text" name ="txtPassword"><br />
-
<br />
-
Department</b>
-
<select name = "1stDepartment">
-
<option value="employee.htm">Employee</option>
-
<option value="customer.htm">Customer</option>
-
<option value="administration.htm">Administration</option>
-
<option value="finance.htm">Finance</option>
-
<option value="hr.htm">HR</option>
-
<option value="it.htm">IT</option>
-
<option value="managment.htm">Managment</option>
-
<option value="manufacturing.htm">Manufacturing</option>
-
<option value="marketing.htm">Marketing</option>
-
<option value="webmaster.htm">Webmaster</option>
-
</select><br />
-
<br />
-
<input type="button" name= "btnLogin" value="Go to the Department Web Site" onClick ="login()" >
-
-
<input type="reset" name= "btnClear" value="Clear Form">
-
-
-
</form>
-
-
<script language = "JavaScript">
-
function login(strUserName){
-
var strUserName, strPassword, strDepartment;
-
strUserName = document.frmlogin.txtUserName.value;
-
strPassword = document.frmlogin.txtPassword.value;
-
strDepartment = document.frmlogin.value;
-
-
switch (strUserName){
-
case "kFoster":
-
if (strPassword == "MST3K"){
-
location.href= strDepartment;
-
}
-
else{
-
location.href= "loginFormJS.htm";
-
}
-
break;
-
case "CSchawab":
-
if (strPassword == "OKC802"){
-
location.href= strDepartment;
-
}
-
else{
-
location.href= "loginFormJS.htm";
-
}
-
break;
-
case "FHelms":
-
if (strPassword == "telcom52"){
-
location.href= strDepartment;
-
}
-
else{
-
location.href= "loginFormJS.htm";
-
}
-
break;
-
case "kShea":
-
if (strPassword == "Ghost716"){
-
location.href= strDepartment;
-
}
-
else{
-
location.href= "loginFormJS.htm";
-
}
-
break;
-
}
-
-
-
}
-
</script>
Heya, MCC.
JavaScript CODE tags make your JavaScript easier to read:
[CODE=javascript]
JavaScript code goes here.
[/CODE]
Try alert()ing strUserName before your switch to make sure that you're getting a value, and to confirm that the login() function is getting evaluated.
mcc, on line 2 in your Javascript, remove the strUsername argument. You're not using it anyway.
For the strDepartment, rename the select so that it doesn't start with a number.
Then, access the select element properly like you have with the username and password.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: D. Alvarado |
last post by:
Hello,
I am trying to open a window containing an image and I would like
the image to be flush against the window -- i.e. have no padding or
border. Can I make this happen with a single call to a...
|
by: Larry Bud |
last post by:
Wanting to use a technology I saw for one of our apps.
We have several apps that a user logs in at on the same page. The app
is determined by a drop down. User credentials are checked,...
|
by: IndyChris |
last post by:
I've got a button my webpage that when clicked will open another
window. Different criteria on the page will deteremine which window
gets opened when the button is clicked. I have a switch...
|
by: bbrewder |
last post by:
I am struggling with some MSAccess automation issues. Basically, we
have a .Net application that uses MSAccess for reporting (legacy
code). We are able to launch MSAccess fine and even work with...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |