473,796 Members | 2,728 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 1501
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
11099
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 = window.open('images/KJV-THANKS.gif', 'Thanks', 'width=243,height=420,'); cwin.focus();
3
2138
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 blank, the user is redirected to the login page. A header on each page checks this. Now, some...
0
1914
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 opens, opens behind the parent window. I was really hoping that it would open in front. I believe that...
0
2026
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 http://support.microsoft.com/default.aspx?scid=kb;en-us;317113&Product=vbNET for info on how to do this). The problem that we are running into is that if our Access...
0
10467
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10244
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.