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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SKbirdie
    New Member
    • Aug 2010
    • 7

    #1

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

    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.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <HTML>
    <HEAD>
    <TITLE>eSales Center - Customer Links</TITLE>
    <META HTTP-EQUIV="Cache-Control" CONTENT="No-Cache">
    <META HTTP-EQUIV="Pragma" CONTENT="No-Cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    
    
    <SCRIPT LANGUAGE="SpeedScript">
    
    {shared/esalesvars.i}
    {shared/validate-session.i}
    {shared/pp-global.i}
    
    assign cLogin = if trim(cLogin) = "" then get-value("operinit") else cLogin.
    
    </SCRIPT>
    </HEAD>
    <BODY>
    <SCRIPT LANGUAGE="javascript">
    
    switch (cLogin)
    {
         case "12102":
              <a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />
              break
         case "134965":
              <a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />
              break
         case "13953":
              <a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />
              break
         case "13716":
              <a href="/WI_testweb/13716.xls"><b><font size="3">Matrix</font></b></a><br />
              break
         case "111667":
              <a href="/WI_testweb/111677.xls"><b><font size="3">Matrix</font></b></a><br />
    	      break
         default:
     	 	  window.alert("This account does not have a custom matrix");
     }
    </SCRIPT>
    </BODY>
    </HTML>
    Last edited by Dormilich; Aug 26 '10, 11:36 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    in this case, you don’t even need a switch() statement.
    Code:
    // the language attribute is outdated
    <SCRIPT tytpe="text/javascript">
    // <font> is deprecated for ages
    // you should use CSS for layout & styling
    var matrix = {
    	12102: 12102,
    	134965: 12102
    	// etc
    };
    document.body.innerHTML = '<a href="/WI_testweb/' + matrix[cLogin] + '.xls">Matrix</a>';
    </SCRIPT>
    Last edited by Dormilich; Aug 26 '10, 11:44 PM.

    Comment

    • SKbirdie
      New Member
      • Aug 2010
      • 7

      #3
      this did not work for me.

      Comment

      • SKbirdie
        New Member
        • Aug 2010
        • 7

        #4
        I finally did get some code I got of a different blog to work so thanks for all the help.

        Comment

        Working...