By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 1,964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

Nested If/else in JS with <a href actions.

P: 7
I am writting a large if / else tree in an existing website. My include libraries have to be put into the html program using a scripting language called SpeedScript. These includes bring in the login data that I am testing in my if tree. Instead of using the if/else I am trying a switch.

I need to know how to write this if/else tree / switch statement. I am brand new to Javascript. Here is the code I currently have that is not working.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2.  
  3. <HTML>
  4. <HEAD>
  5. <TITLE>eSales Center - Customer Links</TITLE>
  6. <META HTTP-EQUIV="Cache-Control" CONTENT="No-Cache">
  7. <META HTTP-EQUIV="Pragma" CONTENT="No-Cache">
  8. <META HTTP-EQUIV="Expires" CONTENT="0">
  9.  
  10.  
  11. <SCRIPT LANGUAGE="SpeedScript">
  12.  
  13. {shared/esalesvars.i}
  14. {shared/validate-session.i}
  15. {shared/pp-global.i}
  16.  
  17. assign cLogin = if trim(cLogin) = "" then get-value("operinit") else cLogin.
  18.  
  19. </SCRIPT>
  20. </HEAD>
  21. <BODY>
  22. <SCRIPT LANGUAGE="javascript">
  23.  
  24. switch (cLogin)
  25. {
  26.      case "12102":
  27.           <a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />
  28.           break
  29.      case "134965":
  30.           <a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />
  31.           break
  32.      case "13953":
  33.           <a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />
  34.           break
  35.      case "13716":
  36.           <a href="/WI_testweb/13716.xls"><b><font size="3">Matrix</font></b></a><br />
  37.           break
  38.      case "111667":
  39.           <a href="/WI_testweb/111677.xls"><b><font size="3">Matrix</font></b></a><br />
  40.           break
  41.      default:
  42.             window.alert("This account does not have a custom matrix");
  43.  }
  44. </SCRIPT>
  45. </BODY>
  46. </HTML>
Aug 26 '10 #1
Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
in this case, you don’t even need a switch() statement.
Expand|Select|Wrap|Line Numbers
  1. // the language attribute is outdated
  2. <SCRIPT tytpe="text/javascript">
  3. // <font> is deprecated for ages
  4. // you should use CSS for layout & styling
  5. var matrix = {
  6.     12102: 12102,
  7.     134965: 12102
  8.     // etc
  9. };
  10. document.body.innerHTML = '<a href="/WI_testweb/' + matrix[cLogin] + '.xls">Matrix</a>';
  11. </SCRIPT>
Aug 26 '10 #2

P: 7
this did not work for me.
Aug 27 '10 #3

P: 7
I finally did get some code I got of a different blog to work so thanks for all the help.
Aug 27 '10 #4

Post your reply

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