473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

opening a new window with a switch case

mcc
3
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 1481
epots9
1,351 Expert 1GB
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
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
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
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 Expert 4TB
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.
Sep 11 '07 #5
acoder
16,027 Expert Mod 8TB
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
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...
3
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,...
0
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...
0
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...
0
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,...

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.