473,586 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

opening a new window with a switch case

mcc
3 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. <form method = "post" name= "frmlogin" action = "javascript:void(0)"> 
  2.  
  3. User Name<br />
  4. <input type ="text" name ="txtUserName"><br />
  5. <br />
  6. Password<br />
  7. <input type ="text" name ="txtPassword"><br />
  8. <br />
  9. Department</b>
  10. <select name = "1stDepartment">
  11. <option value="employee.htm">Employee</option>
  12. <option value="customer.htm">Customer</option>
  13. <option value="administration.htm">Administration</option>
  14. <option value="finance.htm">Finance</option>
  15. <option value="hr.htm">HR</option>
  16. <option value="it.htm">IT</option>
  17. <option value="managment.htm">Managment</option>
  18. <option value="manufacturing.htm">Manufacturing</option>
  19. <option value="marketing.htm">Marketing</option>
  20. <option value="webmaster.htm">Webmaster</option>
  21. </select><br />
  22. <br />
  23. <input type="button" name= "btnLogin" value="Go to the Department Web Site" onClick ="login()" > 
  24.  
  25. <input type="reset" name= "btnClear" value="Clear Form">
  26.  
  27.  
  28. </form>
  29.  
  30. <script language = "JavaScript">
  31. function login(strUserName){
  32. var strUserName, strPassword, strDepartment;
  33. strUserName = document.frmlogin.txtUserName.value;
  34. strPassword = document.frmlogin.txtPassword.value;
  35. strDepartment = document.frmlogin.value;
  36.  
  37. switch (strUserName){
  38.  case "kFoster":
  39.   if (strPassword = "MST3K"){
  40.     window.location.href= ("strDepartment.htm");
  41.     }
  42.     else{
  43.     location.href= ("loginFormJS.htm");
  44.     }
  45.     break;
  46.  case "CSchawab":
  47.   if (strPassword = "OKC802"){
  48.     location.href= ("strDepartment.htm");
  49.     }
  50.     else{
  51.     location.href= ("loginFormJS.htm");
  52.     }
  53.     break;
  54.  case "FHelms":
  55.   if (strPassword = "telcom52"){
  56.     location.href= ("strDepartment.htm");
  57.     }
  58.     else{
  59.     location.href= ("loginFormJS.htm");
  60.     }
  61.     break;
  62.  case "kShea":
  63.   if (strPassword = "Ghost716"){
  64.     location.href= ("strDepartment.htm");
  65.     }
  66.     else{
  67.     location.href= ("loginFormJS.htm");
  68.     }
  69.     break;
  70.         }
  71.  
  72.  
  73.       }
  74. </script>
Sep 10 '07 #1
5 1494
epots9
1,351 Recognized Expert Top Contributor
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.
Sep 10 '07 #2
mcc
3 New Member
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!
Sep 10 '07 #3
mcc
3 New Member
Thanks for the welcome...forgo t 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
Expand|Select|Wrap|Line Numbers
  1. <form method = "post" name= "frmlogin" action = "javascript:void(0)"> 
  2.  
  3. User Name<br />
  4. <input type ="text" name ="txtUserName"><br />
  5. <br />
  6. Password<br />
  7. <input type ="text" name ="txtPassword"><br />
  8. <br />
  9. Department</b>
  10. <select name = "1stDepartment">
  11. <option value="employee.htm">Employee</option>
  12. <option value="customer.htm">Customer</option>
  13. <option value="administration.htm">Administration</option>
  14. <option value="finance.htm">Finance</option>
  15. <option value="hr.htm">HR</option>
  16. <option value="it.htm">IT</option>
  17. <option value="managment.htm">Managment</option>
  18. <option value="manufacturing.htm">Manufacturing</option>
  19. <option value="marketing.htm">Marketing</option>
  20. <option value="webmaster.htm">Webmaster</option>
  21. </select><br />
  22. <br />
  23. <input type="button" name= "btnLogin" value="Go to the Department Web Site" onClick ="login()" > 
  24.  
  25. <input type="reset" name= "btnClear" value="Clear Form">
  26.  
  27.  
  28. </form>
  29.  
Expand|Select|Wrap|Line Numbers
  1. <script language = "JavaScript">
  2. function login(strUserName){
  3. var strUserName, strPassword, strDepartment;
  4. strUserName = document.frmlogin.txtUserName.value;
  5. strPassword = document.frmlogin.txtPassword.value;
  6. strDepartment = document.frmlogin.value;
  7.  
  8. switch (strUserName){
  9.  case "kFoster":
  10.   if (strPassword == "MST3K"){
  11.     location.href= strDepartment;
  12.     }
  13.     else{
  14.     location.href= "loginFormJS.htm";
  15.     }
  16.     break;
  17.  case "CSchawab":
  18.   if (strPassword == "OKC802"){
  19.     location.href= strDepartment;
  20.     }
  21.     else{
  22.     location.href= "loginFormJS.htm";
  23.     }
  24.     break;
  25.  case "FHelms":
  26.   if (strPassword == "telcom52"){
  27.     location.href= strDepartment;
  28.     }
  29.     else{
  30.     location.href= "loginFormJS.htm";
  31.     }
  32.     break;
  33.  case "kShea":
  34.   if (strPassword == "Ghost716"){
  35.     location.href= strDepartment;
  36.     }
  37.     else{
  38.     location.href= "loginFormJS.htm";
  39.     }
  40.     break;
  41.         }
  42.  
  43.  
  44.       }
  45. </script>
Sep 10 '07 #4
pbmods
5,821 Recognized Expert Expert
Heya, MCC.

JavaScript CODE tags make your JavaScript easier to read:
[CODE=javascrip t]
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.
Sep 11 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
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.
Sep 11 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

14
11057
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 window.open function? I would prefer not to create a separate HTML page. So far all I have is the basic var cwin =...
3
2131
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, response.redirect to the application. The user ID is stored in a session variable which determines if the user is logged in. When the session var goes...
0
1904
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 statement in my code and then I set up javascript that I register back to the client. This is all working fine except for one thing. The window that...
0
2015
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 the MSAccess COM objects to run our reports (using GetObject(<MDB Path>) - see...
0
7912
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8202
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.